diff --git a/example/lib/main.dart b/example/lib/main.dart index c4f1d9a..5f4f581 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -26,10 +26,13 @@ class _MyAppState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ 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, diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index b342ae1..873356e 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -9,6 +9,8 @@ export 'country_code.dart'; class CountryCodePicker extends StatefulWidget { final ValueChanged onChanged; + //Exposed new method to get the initial information of the country + final ValueChanged getInitialData; final String initialSelection; final List 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 { 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 { widget.onChanged(e); } } + + void _getInitialSelectedData(CountryCode initialData){ + if(widget.getInitialData != null){ + widget.getInitialData(initialData); + } + } }