fix : some ui and
This commit is contained in:
24
packages/core/lib/utils/first_digit_decimal_formatter.dart
Normal file
24
packages/core/lib/utils/first_digit_decimal_formatter.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class FirstDigitDecimalFormatter extends TextInputFormatter {
|
||||
@override
|
||||
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
|
||||
String digit = newValue.text.replaceAll(RegExp(r'[^0-9]'), "");
|
||||
late String res;
|
||||
|
||||
if (digit.isEmpty) {
|
||||
return newValue.copyWith(text: '');
|
||||
}
|
||||
|
||||
if (digit.length == 1) {
|
||||
res = digit;
|
||||
} else {
|
||||
res = '${digit[0]}.${digit.substring(1)}';
|
||||
}
|
||||
|
||||
return TextEditingValue(
|
||||
text: res,
|
||||
selection: TextSelection.collapsed(offset: res.length),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,3 +14,4 @@ export 'number_utils.dart';
|
||||
export 'parser.dart';
|
||||
export 'route_utils.dart';
|
||||
export 'separator_input_formatter.dart';
|
||||
export 'first_digit_decimal_formatter.dart';
|
||||
|
||||
Reference in New Issue
Block a user