diff --git a/example/lib/main.dart b/example/lib/main.dart index 0c0ee7f..ad5a759 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( diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 063244b..e522a69 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -22,6 +22,9 @@ class CountryCodePicker extends StatefulWidget { final bool enabled; final TextOverflow textOverflow; + /// the size of the selection dialog + final Size dialogSize; + /// used to customize the country list final List customList; @@ -74,7 +77,9 @@ class CountryCodePicker extends StatefulWidget { this.textOverflow = TextOverflow.ellipsis, this.comparator, this.customList, - }); + this.dialogSize, + Key key, + }) : super(key: key); @override State createState() { @@ -100,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, - child: widget.builder(selectedItem), + 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, @@ -202,7 +207,7 @@ class _CountryCodePickerState extends State { super.initState(); } - void _showSelectionDialog() { + void showCountryCodePickerDialog() { showDialog( context: context, builder: (_) => SelectionDialog( @@ -214,6 +219,7 @@ class _CountryCodePickerState extends State { searchStyle: widget.searchStyle, showFlag: widget.showFlag || (widget.showFlagDialog == true), flagWidth: widget.flagWidth, + size: widget.dialogSize, ), ).then((e) { if (e != null) { diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index ac46393..15d0a65 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -10,6 +10,7 @@ class SelectionDialog extends StatefulWidget { final WidgetBuilder emptySearchBuilder; final bool showFlag; final double flagWidth; + final Size size; /// elements passed as favorite final List favoriteElements; @@ -24,6 +25,7 @@ class SelectionDialog extends StatefulWidget { this.searchStyle, this.showFlag, this.flagWidth = 32, + this.size, }) : assert(searchDecoration != null, 'searchDecoration must not be null!'), this.searchDecoration = searchDecoration.copyWith(prefixIcon: Icon(Icons.search)), @@ -64,8 +66,9 @@ class _SelectionDialogState extends State { ), children: [ Container( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height * 0.7, + width: widget.size?.width ?? MediaQuery.of(context).size.width, + height: + widget.size?.height ?? MediaQuery.of(context).size.height * 0.7, child: ListView( children: [ widget.favoriteElements.isEmpty