Browse Source

限制提现金额2位小数

ios
王子贤 3 months ago
parent
commit
d6b699f0d2
1 changed files with 41 additions and 1 deletions
  1. 42
      lib/pages/mine/withdraw_page.dart

42
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/add_bankcard_page.dart';
import 'package:dating_touchme_app/pages/mine/withdraw_history_page.dart'; import 'package:dating_touchme_app/pages/mine/withdraw_history_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@ -195,7 +196,10 @@ class WithdrawPage extends StatelessWidget {
Expanded( Expanded(
child: TextField( child: TextField(
controller: controller.withdrawMoneyController.value, controller: controller.withdrawMoneyController.value,
keyboardType: TextInputType.number,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
DecimalTextInputFormatter(decimalRange: 2),
],
style: TextStyle( style: TextStyle(
fontSize: ScreenUtil().setWidth(22), fontSize: ScreenUtil().setWidth(22),
height: 1 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;
}
}
Loading…
Cancel
Save