Exposed method to get the country information of the initial selection
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user