@@ -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
0 commit comments