Skip to content

Commit 1d6f594

Browse files
committed
Fixed #116
1 parent 70f761b commit 1d6f594

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## [2.10.6]
2+
- Fixed https://github.com/caseyryan/flutter_multi_formatter/issues/122 by adding triggerOnCountrySelectedInitially param to CountryDropdown
13
## [2.10.5]
24
- CountryDropdown can now be filtered. If you need it to show only a
35
predefined list of countries. Just pass "filter" parameter like this

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ packages:
8989
path: ".."
9090
relative: true
9191
source: path
92-
version: "2.10.5"
92+
version: "2.10.6"
9393
flutter_test:
9494
dependency: "direct dev"
9595
description: flutter

lib/formatters/formatter_utils.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ String toNumericString(
5757
if (mantissaSeparator == '.') {
5858
inputString = inputString.replaceAll(',', '');
5959
} else if (mantissaSeparator == ',') {
60-
inputString = inputString.replaceAll('.', '').replaceAll(',', '.');
60+
final fractionSep = _detectFractionSeparator(inputString);
61+
if (fractionSep != null) {
62+
inputString = inputString.replaceAll(fractionSep, '%FRAC%');
63+
}
64+
inputString = inputString.replaceAll('.', '').replaceAll('%FRAC%', '.');
6165
}
6266
var startsWithPeriod = numericStringStartsWithOrphanPeriod(
6367
inputString,
@@ -552,8 +556,7 @@ String toCurrencyString(
552556
}
553557

554558
final str = sb.toString();
555-
final evenPart =
556-
addedMantissaSeparator ? str.substring(0, str.indexOf('.')) : str;
559+
final evenPart = addedMantissaSeparator ? str.substring(0, str.indexOf('.')) : str;
557560

558561
int skipEvenNumbers = 0;
559562
String shorteningName = '';

lib/widgets/country_dropdown.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CountryDropdown extends StatefulWidget {
3030
final double? menuMaxHeight;
3131
final bool? enableFeedback;
3232
final AlignmentGeometry alignment;
33+
final bool triggerOnCountrySelectedInitially;
3334

3435
/// [filter] if you need a predefined list of countries only,
3536
/// pass it here
@@ -41,12 +42,16 @@ class CountryDropdown extends StatefulWidget {
4142
/// [printCountryName] if true, it will display
4243
/// a country name under its flat and country code while
4344
/// the menu is open
45+
/// [triggerOnCountrySelectedInitially] if you don't want onCountrySelected
46+
/// to be triggered right away if you set an initialPhoneCode param,
47+
/// pass false here. Description is here https://github.com/caseyryan/flutter_multi_formatter/issues/122
4448
const CountryDropdown({
4549
Key? key,
4650
this.selectedItemBuilder,
4751
this.listItemBuilder,
4852
this.printCountryName = false,
4953
this.initialPhoneCode,
54+
this.triggerOnCountrySelectedInitially = true,
5055
this.filter,
5156
required this.onCountrySelected,
5257
this.elevation = 8,
@@ -84,11 +89,13 @@ class _CountryDropdownState extends State<CountryDropdown> {
8489
(c) => c.phoneCode == widget.initialPhoneCode) ??
8590
_countryItems.first;
8691
}
87-
_widgetsBinding.addPostFrameCallback((timeStamp) {
88-
if (_initialValue != null) {
89-
widget.onCountrySelected(_initialValue!);
90-
}
91-
});
92+
if (widget.triggerOnCountrySelectedInitially && _initialValue != null) {
93+
_widgetsBinding.addPostFrameCallback((timeStamp) {
94+
if (_initialValue != null) {
95+
widget.onCountrySelected(_initialValue!);
96+
}
97+
});
98+
}
9299
super.initState();
93100
}
94101

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.10.5
3+
version: 2.10.6
44
homepage: https://github.com/caseyryan/flutter_multi_formatter
55

66
environment:

0 commit comments

Comments
 (0)