From 71ca7a0b3472941a438cf969d19c8ff76805e6bf Mon Sep 17 00:00:00 2001 From: Benni Heiss Date: Tue, 26 Mar 2019 11:20:17 +0100 Subject: [PATCH 1/2] refactored selectiondialog _buildoption OnlyCountrymode now also displays only country when closed width doesn't change on search --- example/lib/main.dart | 1 + lib/country_code_picker.dart | 8 ++-- lib/selection_dialog.dart | 82 +++++++++++++----------------------- 3 files changed, 36 insertions(+), 55 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 37aaabe..0d937fb 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -26,6 +26,7 @@ class _MyAppState extends State { onChanged: print, // Initial selection and favorite can be one of code ('IT') OR dial_code('+39') initialSelection: 'IT', + // showCountryOnly: true, favorite: ['+39', 'FR']), ))); } diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 3a48ca0..9b02493 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -1,4 +1,3 @@ - library country_code_picker; import 'package:country_code_picker/country_code.dart'; @@ -67,7 +66,9 @@ class _CountryCodePickerState extends State { ), Flexible( child: Text( - selectedItem.toString(), + widget.showCountryOnly + ? selectedItem.toCountryStringOnly() + : selectedItem.toString(), style: widget.textStyle ?? Theme.of(context).textTheme.button, ), ), @@ -106,7 +107,8 @@ class _CountryCodePickerState extends State { void _showSelectionDialog() { showDialog( context: context, - builder: (_) => new SelectionDialog(elements, favoriteElements, showCountryOnly: widget.showCountryOnly), + builder: (_) => new SelectionDialog(elements, favoriteElements, + showCountryOnly: widget.showCountryOnly), ).then((e) { if (e != null) { setState(() { diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index 3b991fc..44123be 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -4,13 +4,12 @@ import 'package:flutter/material.dart'; /// selection dialog used for selection of the country code class SelectionDialog extends StatefulWidget { final List elements; - bool showCountryOnly; + final bool showCountryOnly; /// elements passed as favorite final List favoriteElements; - SelectionDialog(this.elements, this.favoriteElements, - {this.showCountryOnly}); + SelectionDialog(this.elements, this.favoriteElements, {this.showCountryOnly}); @override State createState() => new _SelectionDialogState(); @@ -39,31 +38,7 @@ class _SelectionDialogState extends State { ..addAll(widget.favoriteElements .map( (f) => new SimpleDialogOption( - child: Flex( - direction: Axis.horizontal, - children: [ - Flexible( - child: Padding( - padding: - const EdgeInsets.only(right: 16.0), - child: Image.asset( - f.flagUri, - package: 'country_code_picker', - width: 32.0, - ), - ), - ), - Flexible( - fit: FlexFit.tight, - child: new Text( - widget.showCountryOnly - ? f.toCountryStringOnly() - : f.toLongString(), - overflow: TextOverflow.fade, - ), - ), - ], - ), + child: _buildOption(f), onPressed: () { _selectItem(f); }, @@ -75,30 +50,7 @@ class _SelectionDialogState extends State { .map( (e) => new SimpleDialogOption( key: Key(e.toLongString()), - child: Flex( - direction: Axis.horizontal, - children: [ - Flexible( - child: Padding( - padding: const EdgeInsets.only(right: 16.0), - child: Image.asset( - e.flagUri, - package: 'country_code_picker', - width: 32.0, - ), - ), - ), - Flexible( - fit: FlexFit.tight, - child: Text( - widget.showCountryOnly - ? e.toCountryStringOnly() - : e.toLongString(), - overflow: TextOverflow.fade, - ), - ), - ], - ), + child: _buildOption(e), onPressed: () { _selectItem(e); }, @@ -106,6 +58,32 @@ class _SelectionDialogState extends State { ) .toList())); + Widget _buildOption(CountryCode e) { + return Flex( + direction: Axis.horizontal, + children: [ + Flexible( + child: Padding( + padding: const EdgeInsets.only(right: 16.0), + child: Image.asset( + e.flagUri, + package: 'country_code_picker', + width: 32.0, + ), + ), + ), + Flexible( + flex: 10, + fit: FlexFit.tight, + child: Text( + widget.showCountryOnly ? e.toCountryStringOnly() : e.toLongString(), + overflow: TextOverflow.fade, + ), + ), + ], + ); + } + @override void initState() { showedElements = widget.elements; From e69dc5e912c5584841c29ab782b64da39a54596b Mon Sep 17 00:00:00 2001 From: Benni Heiss Date: Tue, 26 Mar 2019 11:49:58 +0100 Subject: [PATCH 2/2] fixed small flags on phones --- example/lib/main.dart | 2 +- lib/selection_dialog.dart | 42 +++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 0d937fb..672c493 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -26,7 +26,7 @@ class _MyAppState extends State { onChanged: print, // Initial selection and favorite can be one of code ('IT') OR dial_code('+39') initialSelection: 'IT', - // showCountryOnly: true, + showCountryOnly: true, favorite: ['+39', 'FR']), ))); } diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index 44123be..c5da25b 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -59,28 +59,32 @@ class _SelectionDialogState extends State { .toList())); Widget _buildOption(CountryCode e) { - return Flex( - direction: Axis.horizontal, - children: [ - Flexible( - child: Padding( - padding: const EdgeInsets.only(right: 16.0), - child: Image.asset( - e.flagUri, - package: 'country_code_picker', - width: 32.0, + return Container( + width: 400, + child: Flex( + direction: Axis.horizontal, + children: [ + Flexible( + child: Padding( + padding: const EdgeInsets.only(right: 16.0), + child: Image.asset( + e.flagUri, + package: 'country_code_picker', + width: 32.0, + ), ), ), - ), - Flexible( - flex: 10, - fit: FlexFit.tight, - child: Text( - widget.showCountryOnly ? e.toCountryStringOnly() : e.toLongString(), - overflow: TextOverflow.fade, + Expanded( + flex: 4, + child: Text( + widget.showCountryOnly + ? e.toCountryStringOnly() + : e.toLongString(), + overflow: TextOverflow.fade, + ), ), - ), - ], + ], + ), ); }