Exposed method to get the country information of the initial selection

This commit is contained in:
Rangana Perera
2019-09-04 13:02:20 +05:30
parent ce9d724747
commit e41d6f2031
2 changed files with 19 additions and 4 deletions

View File

@@ -9,6 +9,8 @@ export 'country_code.dart';
class CountryCodePicker extends StatefulWidget {
final ValueChanged<CountryCode> onChanged;
//Exposed new method to get the initial information of the country
final ValueChanged<CountryCode> getInitialData;
final String initialSelection;
final List<String> favorite;
final TextStyle textStyle;
@@ -33,6 +35,7 @@ class CountryCodePicker extends StatefulWidget {
CountryCodePicker({
this.onChanged,
this.getInitialData,
this.initialSelection,
this.favorite = const [],
this.textStyle,
@@ -117,6 +120,9 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
selectedItem = elements[0];
}
//Change added: get the initial entered country information
_getInitialSelectedData(selectedItem);
favoriteElements = elements
.where((e) =>
widget.favorite.firstWhere(
@@ -156,4 +162,10 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
widget.onChanged(e);
}
}
void _getInitialSelectedData(CountryCode initialData){
if(widget.getInitialData != null){
widget.getInitialData(initialData);
}
}
}