From bb7d3c75c860ef70e6ed4432c11e0b601fe67464 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 16:15:25 +0200 Subject: [PATCH 1/3] refs #59: add dialog size --- lib/country_code_picker.dart | 5 +++++ lib/selection_dialog.dart | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 7e491da..6088deb 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,6 +77,7 @@ class CountryCodePicker extends StatefulWidget { this.textOverflow = TextOverflow.ellipsis, this.comparator, this.customList, + this.dialogSize, }); @override @@ -213,6 +217,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 eb010c4..ae6beb2 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 From c74dcf43ca8334d4f17139732498b27bef225009 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 16:25:19 +0200 Subject: [PATCH 2/3] refs #60: expose state to let use a key to open the dialog --- example/lib/main.dart | 6 +----- lib/country_code_picker.dart | 15 ++++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) 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( From f4a23020bf8bdef80d945737c62dfbc18eefd244 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 16:25:36 +0200 Subject: [PATCH 3/3] fix example --- example/lib/main.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 6b31564..cdebcaf 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -33,7 +33,6 @@ 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',