override didUpdateWidget to react to initlialSelection change

In my application I found this change necessary to change initialSelction on rebuild of the widget tree
This commit is contained in:
Matteo
2020-01-26 16:58:45 +01:00
committed by GitHub
parent 1114515c62
commit 5061b926ee

View File

@@ -132,6 +132,21 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
}
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() {