From 5061b926eee6e0f3337f8c0148d06dc62189a977 Mon Sep 17 00:00:00 2001 From: Matteo Date: Sun, 26 Jan 2020 16:58:45 +0100 Subject: [PATCH 1/2] override didUpdateWidget to react to initlialSelection change In my application I found this change necessary to change initialSelction on rebuild of the widget tree --- lib/country_code_picker.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index dbef894..e7733c5 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -132,6 +132,21 @@ class _CountryCodePickerState extends State { } return _widget; } + + @override + void didUpdateWidget(CountryCodePicker 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() { From eb82bd7067399c639eaf2d64cc95dc5b151e474d Mon Sep 17 00:00:00 2001 From: Matteo Date: Sat, 1 Feb 2020 12:20:06 +0100 Subject: [PATCH 2/2] added call to super.didUpdateWidget(oldWidget); --- lib/country_code_picker.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index e7733c5..05e23ca 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -135,6 +135,7 @@ class _CountryCodePickerState extends State { @override void didUpdateWidget(CountryCodePicker oldWidget) { + super.didUpdateWidget(oldWidget); if(oldWidget.initialSelection != widget.initialSelection) { if (widget.initialSelection != null) { selectedItem = elements.firstWhere(