diff --git a/example/lib/main.dart b/example/lib/main.dart index c65f5d5..6b31564 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -11,11 +11,6 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - @override - void initState() { - super.initState(); - } - @override Widget build(BuildContext context) { return new MaterialApp( @@ -38,6 +33,7 @@ class _MyAppState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ CountryCodePicker( + key: key, onChanged: print, // Initial selection and favorite can be one of code ('IT') OR dial_code('+39') initialSelection: 'IT', diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 6088deb..7dbaac5 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -78,7 +78,8 @@ class CountryCodePicker extends StatefulWidget { this.comparator, this.customList, this.dialogSize, - }); + Key key, + }) : super(key: key); @override State createState() { @@ -104,29 +105,29 @@ class CountryCodePicker extends StatefulWidget { elements = elements.where((c) => countryFilter.contains(c.code)).toList(); } - return _CountryCodePickerState(elements); + return CountryCodePickerState(elements); } } -class _CountryCodePickerState extends State { +class CountryCodePickerState extends State { CountryCode selectedItem; List elements = []; List favoriteElements = []; - _CountryCodePickerState(this.elements); + CountryCodePickerState(this.elements); @override Widget build(BuildContext context) { Widget _widget; if (widget.builder != null) _widget = InkWell( - onTap: _showSelectionDialog, + onTap: showCountryCodePickerDialog, child: widget.builder(selectedItem.localize(context)), ); else { _widget = FlatButton( padding: widget.padding, - onPressed: widget.enabled ? _showSelectionDialog : null, + onPressed: widget.enabled ? showCountryCodePickerDialog : null, child: Flex( direction: Axis.horizontal, mainAxisSize: MainAxisSize.min, @@ -205,7 +206,7 @@ class _CountryCodePickerState extends State { super.initState(); } - void _showSelectionDialog() { + void showCountryCodePickerDialog() { showDialog( context: context, builder: (_) => SelectionDialog(