diff --git a/example/lib/main.dart b/example/lib/main.dart index dc33bff..a92be9c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -43,7 +43,8 @@ class _MyAppState extends State { showFlagDialog: true, comparator: (a, b) => b.name.compareTo(a.name), //Get the country information relevant to the initial selection - onInit: (code) => print("${code.name} ${code.dialCode}"), + onInit: (code) => + print("on init ${code.name} ${code.dialCode}"), ), SizedBox( width: 400, diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 5b5ac9b..c2cdea9 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -163,11 +163,15 @@ class CountryCodePickerState extends State { } @override - void didUpdateWidget(CountryCodePicker oldWidget) { - super.didUpdateWidget(oldWidget); + void didChangeDependencies() { + super.didChangeDependencies(); this.elements = elements.map((e) => e.localize(context)).toList(); - _onInit(selectedItem); + } + + @override + void didUpdateWidget(CountryCodePicker oldWidget) { + super.didUpdateWidget(oldWidget); if (oldWidget.initialSelection != widget.initialSelection) { if (widget.initialSelection != null) {