From d6b699f0d22f736d7e705f71b888eeef13cc27e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AD=90=E8=B4=A4?= Date: Thu, 18 Dec 2025 17:33:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6=E6=8F=90=E7=8E=B0=E9=87=91?= =?UTF-8?q?=E9=A2=9D2=E4=BD=8D=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/mine/withdraw_page.dart | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/pages/mine/withdraw_page.dart b/lib/pages/mine/withdraw_page.dart index 1c65dc7..f6265e9 100644 --- a/lib/pages/mine/withdraw_page.dart +++ b/lib/pages/mine/withdraw_page.dart @@ -6,6 +6,7 @@ import 'package:dating_touchme_app/model/mine/bank_card_data.dart'; import 'package:dating_touchme_app/pages/mine/add_bankcard_page.dart'; import 'package:dating_touchme_app/pages/mine/withdraw_history_page.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; @@ -195,7 +196,10 @@ class WithdrawPage extends StatelessWidget { Expanded( child: TextField( controller: controller.withdrawMoneyController.value, - keyboardType: TextInputType.number, + keyboardType: const TextInputType.numberWithOptions(decimal: true), + inputFormatters: [ + DecimalTextInputFormatter(decimalRange: 2), + ], style: TextStyle( fontSize: ScreenUtil().setWidth(22), height: 1 @@ -582,3 +586,39 @@ class WithdrawPage extends StatelessWidget { } } +class DecimalTextInputFormatter extends TextInputFormatter { + DecimalTextInputFormatter({this.decimalRange = 2}); + + final int decimalRange; + + @override + TextEditingValue formatEditUpdate( + TextEditingValue oldValue, + TextEditingValue newValue, + ) { + final text = newValue.text; + + // 允许空 + if (text.isEmpty) return newValue; + + // 只允许数字和小数点 + if (!RegExp(r'^\d*\.?\d*$').hasMatch(text)) { + return oldValue; + } + + // 只允许一个小数点 + if ('.'.allMatches(text).length > 1) { + return oldValue; + } + + // 限制小数位数 + if (text.contains('.')) { + final parts = text.split('.'); + if (parts.length > 1 && parts[1].length > decimalRange) { + return oldValue; + } + } + + return newValue; + } +} \ No newline at end of file