diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index dbef894..05e23ca 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -132,6 +132,22 @@ class _CountryCodePickerState extends State { } return _widget; } + + @override + void didUpdateWidget(CountryCodePicker oldWidget) { + super.didUpdateWidget(oldWidget); + if(oldWidget.initialSelection != widget.initialSelection) { + if (widget.initialSelection != null) { + selectedItem = elements.firstWhere( + (e) => + (e.code.toUpperCase() == widget.initialSelection.toUpperCase()) || + (e.dialCode == widget.initialSelection.toString()), + orElse: () => elements[0]); + } else { + selectedItem = elements[0]; + } + } + } @override initState() {