From 894ffd7c9ea6562b2b33dd7025f729ab1acb8ec2 Mon Sep 17 00:00:00 2001 From: Saif Allah Khaled Date: Thu, 5 Sep 2019 15:47:49 +0200 Subject: [PATCH 1/4] enable custom view widgets; --- lib/country_code_picker.dart | 84 ++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index b342ae1..c906672 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -17,6 +17,7 @@ class CountryCodePicker extends StatefulWidget { final InputDecoration searchDecoration; final TextStyle searchStyle; final WidgetBuilder emptySearchBuilder; + final Widget customWidget; /// shows the name of the country instead of the dialcode final bool showOnlyCountryWhenClosed; @@ -43,7 +44,8 @@ class CountryCodePicker extends StatefulWidget { this.emptySearchBuilder, this.showOnlyCountryWhenClosed = false, this.alignLeft = false, - this.showFlag = true + this.showFlag = true, + this.customWidget, }); @override @@ -71,39 +73,49 @@ class _CountryCodePickerState extends State { _CountryCodePickerState(this.elements); @override - Widget build(BuildContext context) => FlatButton( - child: Flex( - direction: Axis.horizontal, - mainAxisSize: MainAxisSize.min, - children: [ - widget.showFlag ? Flexible( - flex: widget.alignLeft ? 0 : 1, - fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, - child: Padding( - padding: widget.alignLeft - ? const EdgeInsets.only(right: 16.0, left: 8.0) - : const EdgeInsets.only(right: 16.0), - child: Image.asset( - selectedItem.flagUri, - package: 'country_code_picker', - width: 32.0, - ), - ), - ) : Container(), - Flexible( - fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, - child: Text( - widget.showOnlyCountryWhenClosed - ? selectedItem.toCountryStringOnly() - : selectedItem.toString(), - style: widget.textStyle ?? Theme.of(context).textTheme.button, - ), + Widget build(BuildContext context) { + Widget _widget; + if (widget.customWidget != null) + _widget = widget.customWidget; + else { + _widget = Flex( + direction: Axis.horizontal, + mainAxisSize: MainAxisSize.min, + children: [ + widget.showFlag + ? Flexible( + flex: widget.alignLeft ? 0 : 1, + fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, + child: Padding( + padding: widget.alignLeft + ? const EdgeInsets.only(right: 16.0, left: 8.0) + : const EdgeInsets.only(right: 16.0), + child: Image.asset( + selectedItem.flagUri, + package: 'country_code_picker', + width: 32.0, + ), + ), + ) + : Container(), + Flexible( + fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, + child: Text( + widget.showOnlyCountryWhenClosed + ? selectedItem.toCountryStringOnly() + : selectedItem.toString(), + style: widget.textStyle ?? Theme.of(context).textTheme.button, ), - ], - ), - padding: widget.padding, - onPressed: _showSelectionDialog, + ), + ], ); + } + return FlatButton( + child: _widget, + padding: widget.padding, + onPressed: _showSelectionDialog, + ); + } @override initState() { @@ -130,16 +142,12 @@ class _CountryCodePickerState extends State { void _showSelectionDialog() { showDialog( context: context, - builder: (_) => - SelectionDialog( - elements, - favoriteElements, + builder: (_) => SelectionDialog(elements, favoriteElements, showCountryOnly: widget.showCountryOnly, emptySearchBuilder: widget.emptySearchBuilder, searchDecoration: widget.searchDecoration, searchStyle: widget.searchStyle, - showFlag: widget.showFlag - ), + showFlag: widget.showFlag), ).then((e) { if (e != null) { setState(() { From 9d6415717163746c87d9aba92287646ce368a9dd Mon Sep 17 00:00:00 2001 From: Saif Allah Khaled Date: Thu, 5 Sep 2019 16:21:10 +0200 Subject: [PATCH 2/4] enable custom view widgets; --- lib/country_code_picker.dart | 71 +++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index c906672..412f38d 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -76,45 +76,48 @@ class _CountryCodePickerState extends State { Widget build(BuildContext context) { Widget _widget; if (widget.customWidget != null) - _widget = widget.customWidget; + _widget = InkWell( + onTap: _showSelectionDialog, + child: widget.customWidget, + ); else { - _widget = Flex( - direction: Axis.horizontal, - mainAxisSize: MainAxisSize.min, - children: [ - widget.showFlag - ? Flexible( - flex: widget.alignLeft ? 0 : 1, - fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, - child: Padding( - padding: widget.alignLeft - ? const EdgeInsets.only(right: 16.0, left: 8.0) - : const EdgeInsets.only(right: 16.0), - child: Image.asset( - selectedItem.flagUri, - package: 'country_code_picker', - width: 32.0, + _widget = FlatButton( + padding: widget.padding, + onPressed: _showSelectionDialog, + child: Flex( + direction: Axis.horizontal, + mainAxisSize: MainAxisSize.min, + children: [ + widget.showFlag + ? Flexible( + flex: widget.alignLeft ? 0 : 1, + fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, + child: Padding( + padding: widget.alignLeft + ? const EdgeInsets.only(right: 16.0, left: 8.0) + : const EdgeInsets.only(right: 16.0), + child: Image.asset( + selectedItem.flagUri, + package: 'country_code_picker', + width: 32.0, + ), ), - ), - ) - : Container(), - Flexible( - fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, - child: Text( - widget.showOnlyCountryWhenClosed - ? selectedItem.toCountryStringOnly() - : selectedItem.toString(), - style: widget.textStyle ?? Theme.of(context).textTheme.button, + ) + : Container(), + Flexible( + fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, + child: Text( + widget.showOnlyCountryWhenClosed + ? selectedItem.toCountryStringOnly() + : selectedItem.toString(), + style: widget.textStyle ?? Theme.of(context).textTheme.button, + ), ), - ), - ], + ], + ), ); } - return FlatButton( - child: _widget, - padding: widget.padding, - onPressed: _showSelectionDialog, - ); + return _widget; } @override From 5f7e5c5154e0d687cc08b7c4398d17b7d087bf04 Mon Sep 17 00:00:00 2001 From: Saif Allah Khaled Date: Thu, 5 Sep 2019 19:28:03 +0200 Subject: [PATCH 3/4] Pump Version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index b6fbff8..2c257ba 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: country_code_picker description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox -version: 1.1.7 +version: 1.1.8 author: Salvatore-Giordano homepage: https://github.com/Salvatore-Giordano/CountryCodePicker From fe30025f178ec55bcfcf92cb33046eaad8155f59 Mon Sep 17 00:00:00 2001 From: Saif Allah Khaled Date: Thu, 5 Sep 2019 19:32:36 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 143 ++++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a623b2..4fd03c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,77 +1,78 @@ -## 0.0.1 - -Initial release - -## 0.0.2 - -Add favorite countries option. - -## 0.1.0 - -Removed flags in iOS because they show up weirdly. - -## 0.1.1 - -Tested with dart 2 - -## 0.1.2 - -Favorite and initial selection can be one of code or dial code - -## 0.1.3 - -Favorite and initial selection can be one of code or dial code - -## 0.2.0 - -Now onChanged has a full CElement as argument and not only a string. (issue #4) - -## 0.2.1 - -Added some documentation - -## 0.2.2 - -Added textStyle and padding as widget parameters - -## 1.0.0 - -Use png flags instead of a font - -## 1.0.1 - -Correct README and update screenshots - -## 1.0.2 - -Update framework compatiblity - -## 1.0.3 - -Update flags dimension to reduce application size - -## 1.0.4 - -Update country name with translated version - -## 1.1.0 - -Changed CElement with CountryCode and fix error on favorite null - -## 1.1.1 - -Update allowed dart version and modify description - -## 1.1.4 - -Add possibility to show only country name - -## 1.1.5 - -OnlyCountrymode now also displays only the country on Textwidget when closed. +## 1.1.8 +- Added Ability to render custom Widget instead of package one's, through [customWidget] param [@Saifallak](https://github.com/Saifallak). ## 1.1.7 Flag is now optional. Fix bug on initState. +## 1.1.5 +OnlyCountrymode now also displays only the country on Textwidget when closed. + +## 1.1.4 + +Add possibility to show only country name + +## 1.1.1 + +Update allowed dart version and modify description + +## 1.1.0 + +Changed CElement with CountryCode and fix error on favorite null + +## 1.0.4 + +Update country name with translated version + +## 1.0.3 + +Update flags dimension to reduce application size + +## 1.0.2 + +Update framework compatiblity + +## 1.0.1 + +Correct README and update screenshots + +## 1.0.0 + +Use png flags instead of a font + +## 0.2.2 + +Added textStyle and padding as widget parameters + +## 0.2.1 + +Added some documentation + +## 0.2.0 + +Now onChanged has a full CElement as argument and not only a string. (issue #4) + +## 0.1.3 + +Favorite and initial selection can be one of code or dial code + +## 0.1.2 + +Favorite and initial selection can be one of code or dial code + +## 0.1.1 + +Tested with dart 2 + +## 0.1.0 + +Removed flags in iOS because they show up weirdly. + +## 0.0.2 + +Add favorite countries option. + +## 0.0.1 + +Initial release