Skip to content

Commit 6d8bdd1

Browse files
committed
more fixes
1 parent a6b2d0c commit 6d8bdd1

7 files changed

Lines changed: 68 additions & 80 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## [2.9.14]
22
- Fixed https://github.com/caseyryan/flutter_multi_formatter/issues/111
3+
- Fixed https://github.com/caseyryan/flutter_multi_formatter/issues/110
4+
- Fixed https://github.com/caseyryan/flutter_multi_formatter/issues/108
5+
- Fixed https://github.com/caseyryan/flutter_multi_formatter/issues/107
36
## [2.9.11]
47
- Added promptTonesForPinyin() static function to PinyinUtils.
58
It can give you a list of its vowels with all possible tones

example/lib/pages/money_format_page.dart

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ class _MoneyFormatPageState extends State<MoneyFormatPage> {
1616

1717
@override
1818
Widget build(BuildContext context) {
19-
print(
20-
toCurrencyString(
21-
'M1,1111'.toString(),
22-
mantissaLength: 0,
23-
thousandSeparator: ThousandSeparator.Comma,
24-
leadingSymbol: 'M',
25-
),
26-
);
27-
2819
return Unfocuser(
2920
child: Scaffold(
3021
appBar: AppBar(
@@ -62,15 +53,10 @@ class _MoneyFormatPageState extends State<MoneyFormatPage> {
6253
),
6354
inputFormatters: [
6455
CurrencyInputFormatter(
65-
mantissaLength: 0,
66-
thousandSeparator: ThousandSeparator.Comma,
67-
leadingSymbol: 'M',
68-
),
69-
// CurrencyInputFormatter(
70-
// thousandSeparator: ThousandSeparator.Space,
71-
// mantissaLength: 2,
72-
// trailingSymbol: "\$",
73-
// )
56+
thousandSeparator: ThousandSeparator.Space,
57+
mantissaLength: 2,
58+
trailingSymbol: "\$",
59+
)
7460
],
7561
),
7662
SizedBox(
@@ -318,7 +304,8 @@ class _MoneyFormatPageState extends State<MoneyFormatPage> {
318304
CurrencyInputFormatter(
319305
leadingSymbol: CurrencySymbols.DOLLAR_SIGN,
320306
useSymbolPadding: true,
321-
thousandSeparator: ThousandSeparator.SpaceAndPeriodMantissa,
307+
thousandSeparator:
308+
ThousandSeparator.SpaceAndPeriodMantissa,
322309
// ThousandSeparator.Comma,
323310
)
324311
],
@@ -343,7 +330,8 @@ class _MoneyFormatPageState extends State<MoneyFormatPage> {
343330
),
344331
inputFormatters: [
345332
CurrencyInputFormatter(
346-
thousandSeparator: ThousandSeparator.SpaceAndPeriodMantissa,
333+
thousandSeparator:
334+
ThousandSeparator.SpaceAndPeriodMantissa,
347335
trailingSymbol: ' USD',
348336
// ThousandSeparator.Comma,
349337
)
@@ -369,7 +357,8 @@ class _MoneyFormatPageState extends State<MoneyFormatPage> {
369357
),
370358
inputFormatters: [
371359
CurrencyInputFormatter(
372-
thousandSeparator: ThousandSeparator.SpaceAndCommaMantissa,
360+
thousandSeparator:
361+
ThousandSeparator.SpaceAndCommaMantissa,
373362
trailingSymbol: ' U',
374363
// ThousandSeparator.Comma,
375364
)

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ packages:
9696
path: ".."
9797
relative: true
9898
source: path
99-
version: "2.9.11"
99+
version: "2.9.14"
100100
flutter_test:
101101
dependency: "direct dev"
102102
description: flutter

lib/formatters/currency_input_formatter.dart

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class CurrencyInputFormatter extends TextInputFormatter {
5555
final int? maxTextLength;
5656
final ValueChanged<num>? onValueChange;
5757

58+
bool _printDebugInfo = false;
59+
5860
/// [thousandSeparator] specifies what symbol will be used to separate
5961
/// each block of 3 digits, e.g. [ThousandSeparator.Comma] will format
6062
/// million as 1,000,000
@@ -127,7 +129,6 @@ class CurrencyInputFormatter extends TextInputFormatter {
127129
final oldCaretIndex = max(oldValue.selection.start, oldValue.selection.end);
128130
final newCaretIndex = max(newValue.selection.start, newValue.selection.end);
129131
var newText = newValue.text;
130-
// print(newText);
131132
final newAsNumeric = toNumericString(
132133
newText,
133134
allowPeriod: true,
@@ -137,14 +138,18 @@ class CurrencyInputFormatter extends TextInputFormatter {
137138

138139
var oldText = oldValue.text;
139140
if (oldValue == newValue) {
140-
// print('RETURN 0 ${oldValue.text}');
141+
if (_printDebugInfo) {
142+
print('RETURN 0 ${oldValue.text}');
143+
}
141144
return newValue;
142145
}
143146
bool isErasing = newText.length < oldText.length;
144147
if (isErasing) {
145148
if (mantissaLength == 0 && oldCaretIndex == oldValue.text.length) {
146149
if (trailingLength > 0) {
147-
// print('RETURN 1 ${oldValue.text}');
150+
if (_printDebugInfo) {
151+
print('RETURN 1 ${oldValue.text}');
152+
}
148153
return oldValue.copyWith(
149154
selection: TextSelection.collapsed(
150155
offset: min(
@@ -159,7 +164,9 @@ class CurrencyInputFormatter extends TextInputFormatter {
159164
shorterString: newText,
160165
longerString: oldText,
161166
)) {
162-
// print('RETURN 2 ${oldValue.text}');
167+
if (_printDebugInfo) {
168+
print('RETURN 2 ${oldValue.text}');
169+
}
163170
return oldValue.copyWith(
164171
selection: TextSelection.collapsed(
165172
offset: min(
@@ -171,7 +178,9 @@ class CurrencyInputFormatter extends TextInputFormatter {
171178
}
172179
} else {
173180
if (_containsIllegalChars(newText)) {
174-
// print('RETURN 3 ${oldValue.text}');
181+
if (_printDebugInfo) {
182+
print('RETURN 3 ${oldValue.text}');
183+
}
175184
return oldValue;
176185
}
177186
}
@@ -194,7 +203,9 @@ class CurrencyInputFormatter extends TextInputFormatter {
194203
newText: newText,
195204
oldText: oldText,
196205
)) {
197-
// print('RETURN 4 ${oldValue.text.length} $oldCaretIndex');
206+
if (_printDebugInfo) {
207+
print('RETURN 4 ${oldValue.text.length} $oldCaretIndex');
208+
}
198209
return oldValue.copyWith(
199210
selection: TextSelection.collapsed(
200211
offset: min(
@@ -211,15 +222,19 @@ class CurrencyInputFormatter extends TextInputFormatter {
211222
oldText: oldText,
212223
caretPosition: newCaretIndex,
213224
)) {
214-
// print('RETURN 5 $newAsCurrency');
225+
if (_printDebugInfo) {
226+
print('RETURN 5 $newAsCurrency');
227+
}
215228
return TextEditingValue(
216229
selection: TextSelection.collapsed(
217230
offset: newCaretIndex,
218231
),
219232
text: newAsCurrency,
220233
);
221234
} else {
222-
// print('RETURN 6 $newAsCurrency');
235+
if (_printDebugInfo) {
236+
print('RETURN 6 $newAsCurrency');
237+
}
223238
int offset = min(
224239
newCaretIndex,
225240
newAsCurrency.length - trailingLength,
@@ -235,7 +250,9 @@ class CurrencyInputFormatter extends TextInputFormatter {
235250

236251
var initialCaretOffset = leadingLength;
237252
if (_isZeroOrEmpty(newAsNumeric)) {
238-
// print('RETURN 7 ${newValue.text}');
253+
if (_printDebugInfo) {
254+
print('RETURN 7 ${newValue.text}');
255+
}
239256
int offset = min(
240257
newValue.text.length,
241258
initialCaretOffset + 1,
@@ -271,7 +288,9 @@ class CurrencyInputFormatter extends TextInputFormatter {
271288
initialCaretOffset += 1;
272289
}
273290
}
274-
// print('RETURN 8 $newAsCurrency');
291+
if (_printDebugInfo) {
292+
print('RETURN 8 $newAsCurrency');
293+
}
275294
return TextEditingValue(
276295
selection: TextSelection.collapsed(
277296
offset: initialCaretOffset,

lib/formatters/formatter_utils.dart

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,25 @@ String toCurrencyString(
501501
}) {
502502
value = value.replaceAll(_spaceRegex, '');
503503
if (value.isEmpty) {
504-
return value;
504+
value = '0';
505505
}
506-
String mSeparator = _getMantissaSeparator(thousandSeparator, mantissaLength);
507-
String tSeparator = _getThousandSeparator(thousandSeparator);
506+
String mSeparator = _getMantissaSeparator(
507+
thousandSeparator,
508+
mantissaLength,
509+
);
510+
String tSeparator = _getThousandSeparator(
511+
thousandSeparator,
512+
);
513+
514+
/// нужно только для того, чтобы недопустить числа начинающиеся с нуля
515+
/// 04.00 и т.д
516+
value = toNumericString(
517+
value,
518+
allowAllZeroes: false,
519+
allowHyphen: true,
520+
allowPeriod: true,
521+
mantissaSeparator: mSeparator,
522+
);
508523
String? fractionalSeparator =
509524
mantissaLength > 0 ? _detectFractionSeparator(value) : null;
510525

@@ -532,7 +547,8 @@ String toCurrencyString(
532547
}
533548

534549
final str = sb.toString();
535-
final evenPart = addedMantissaSeparator ? str.substring(0, str.indexOf('.')) : str;
550+
final evenPart =
551+
addedMantissaSeparator ? str.substring(0, str.indexOf('.')) : str;
536552

537553
int skipEvenNumbers = 0;
538554
String shorteningName = '';
@@ -641,46 +657,13 @@ String toCurrencyString(
641657
return value;
642658
}
643659

644-
/// просто меняет точки и запятые местами
645-
// String _swapCommasAndPeriods(String input) {
646-
// var temp = input;
647-
// if (temp.indexOf('.,') > -1) {
648-
// temp = temp.replaceAll('.,', ',,');
649-
// }
650-
// temp = temp.replaceAll('.', 'PERIOD').replaceAll(',', 'COMMA');
651-
// temp = temp.replaceAll('PERIOD', ',').replaceAll('COMMA', '.');
652-
// return temp;
653-
// }
654-
655660
bool isUnmaskableSymbol(String? symbol) {
656661
if (symbol == null || symbol.length > 1) {
657662
return false;
658663
}
659664
return _isMaskSymbolRegExp.hasMatch(symbol);
660665
}
661666

662-
// String _getRoundedValue(
663-
// String numericString,
664-
// double roundTo,
665-
// ) {
666-
// assert(roundTo != 0.0);
667-
// var numericValue = double.tryParse(numericString) ?? 0.0;
668-
// var result = numericValue / roundTo;
669-
670-
// /// e.g. for a number of 1700 return 1.7, instead of 1
671-
// /// after rounding to 1000
672-
// var remainder = result.remainder(1.0);
673-
// String prepared;
674-
// if (remainder != 0.0) {
675-
// prepared = result.toStringAsFixed(2);
676-
// if (prepared[prepared.length - 1] == '0') {
677-
// prepared = prepared.substring(0, prepared.length - 1);
678-
// }
679-
// return prepared;
680-
// }
681-
// return result.toInt().toString();
682-
// }
683-
684667
/// Checks if currency is fiat
685668
bool isFiatCurrency(String currencyId) {
686669
if (currencyId.length != 3) {
@@ -702,14 +685,6 @@ bool isCryptoCurrency(String currencyId) {
702685
return !isFiatCurrency(currencyId);
703686
}
704687

705-
/// simply adds a period to an existing fractional part
706-
/// or adds an empty fractional part if it was not filled
707-
// String _postProcessMantissa(String mantissaValue, int mantissaLength) {
708-
// if (mantissaLength < 1) return '';
709-
// if (mantissaValue.isNotEmpty) return '.$mantissaValue';
710-
// return '.${List.filled(mantissaLength, '0').join('')}';
711-
// }
712-
713688
/// [character] a character to check if it's a digit against
714689
/// [positiveOnly] if true it will not allow a minus (dash) character
715690
/// to be accepted as a part of a digit

lib/utils/pinyin_utils.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,8 @@ class PinyinUtils {
809809
removePunctuation: removePunctuation,
810810
);
811811
} else {
812-
final maxScoredSentences = _getSentencesWithMaxScore(allPossibleSentences!);
812+
final maxScoredSentences =
813+
_getSentencesWithMaxScore(allPossibleSentences!);
813814
allPossibleSentences.clear();
814815
allPossibleSentences.addAll(maxScoredSentences);
815816
}
@@ -1034,7 +1035,8 @@ class _Sentence {
10341035
}
10351036
if (rankByUse) {
10361037
for (var r in _correctSequence!) {
1037-
List<HanziRankInfo> rankInfo = HanziUtils.findHanziRankByPinyin(r.value);
1038+
List<HanziRankInfo> rankInfo =
1039+
HanziUtils.findHanziRankByPinyin(r.value);
10381040
int rank = rankInfo.firstOrNull?.fequencyRank ?? 10000;
10391041
_totalUseRank += rank;
10401042
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_multi_formatter
22
description: A package of formatters for international phone numbers, credit / debit cards and a masked formatter
3-
version: 2.9.11
3+
version: 2.9.14
44
homepage: https://github.com/caseyryan/flutter_multi_formatter
55

66
environment:

0 commit comments

Comments
 (0)