Merge pull request #40 from ranganaperera/get_initial_date_values
Exposed method to get the country information of the initial selection
This commit is contained in:
@@ -26,10 +26,13 @@ class _MyAppState extends State<MyApp> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
CountryCodePicker(
|
||||
onChanged: print,
|
||||
// Initial selection and favorite can be one of code ('IT') OR dial_code('+39')
|
||||
initialSelection: 'IT',
|
||||
favorite: ['+39', 'FR']),
|
||||
onChanged: print,
|
||||
// Initial selection and favorite can be one of code ('IT') OR dial_code('+39')
|
||||
initialSelection: 'IT',
|
||||
favorite: ['+39', 'FR'],
|
||||
//Get the country information relevant to the initial selection
|
||||
getInitialData: (code) => print("${code.name} ${code.dialCode}"),
|
||||
),
|
||||
SizedBox(
|
||||
width: 400,
|
||||
height: 60,
|
||||
|
||||
@@ -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;
|
||||
@@ -36,6 +38,7 @@ class CountryCodePicker extends StatefulWidget {
|
||||
|
||||
CountryCodePicker({
|
||||
this.onChanged,
|
||||
this.getInitialData,
|
||||
this.initialSelection,
|
||||
this.favorite = const [],
|
||||
this.countryFilter = const [],
|
||||
@@ -127,6 +130,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(
|
||||
@@ -166,4 +172,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