From 5061b926eee6e0f3337f8c0148d06dc62189a977 Mon Sep 17 00:00:00 2001 From: Matteo Date: Sun, 26 Jan 2020 16:58:45 +0100 Subject: [PATCH] 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() {