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:
Salvatore Giordano
2019-12-09 23:09:39 +01:00
committed by GitHub
2 changed files with 19 additions and 4 deletions

View File

@@ -26,10 +26,13 @@ class _MyAppState extends State<MyApp> {
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[ children: <Widget>[
CountryCodePicker( CountryCodePicker(
onChanged: print, onChanged: print,
// Initial selection and favorite can be one of code ('IT') OR dial_code('+39') // Initial selection and favorite can be one of code ('IT') OR dial_code('+39')
initialSelection: 'IT', initialSelection: 'IT',
favorite: ['+39', 'FR']), favorite: ['+39', 'FR'],
//Get the country information relevant to the initial selection
getInitialData: (code) => print("${code.name} ${code.dialCode}"),
),
SizedBox( SizedBox(
width: 400, width: 400,
height: 60, height: 60,

View File

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