diff --git a/CHANGELOG.md b/CHANGELOG.md index d9cdf9d..cd4c1aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -## 1.3.0 +## 1.3.2 + +- Add `enable` property in order to use the disable the button + +## 1.3.1 - Add `flagWidth` property diff --git a/example/lib/main.dart b/example/lib/main.dart index d45fb37..1f105e6 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -76,6 +76,21 @@ class _MyAppState extends State { ), ), ), + SizedBox( + width: 100, + height: 60, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: CountryCodePicker( + enabled: false, + onChanged: print, + initialSelection: 'TF', + showCountryOnly: true, + showOnlyCountryWhenClosed: true, + favorite: ['+39', 'FR'], + ), + ), + ), ], ), ), diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index ea546ad..3df019b 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -19,6 +19,8 @@ class CountryCodePicker extends StatefulWidget { final TextStyle searchStyle; final WidgetBuilder emptySearchBuilder; final Function(CountryCode) builder; + final bool enabled; + final TextOverflow textOverflow; /// shows the name of the country instead of the dialcode final bool showOnlyCountryWhenClosed; @@ -56,6 +58,8 @@ class CountryCodePicker extends StatefulWidget { this.showFlag = true, this.builder, this.flagWidth = 32.0, + this.enabled = true, + this.textOverflow = TextOverflow.ellipsis, }); @override @@ -91,27 +95,26 @@ class _CountryCodePickerState extends State { else { _widget = FlatButton( padding: widget.padding, - onPressed: _showSelectionDialog, + onPressed: widget.enabled ? _showSelectionDialog : null, 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: widget.flagWidth, - ), - ), - ) - : Container(), + if (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: widget.flagWidth, + ), + ), + ), Flexible( fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, child: Text( @@ -119,6 +122,7 @@ class _CountryCodePickerState extends State { ? selectedItem.toCountryStringOnly(context) : selectedItem.toString(), style: widget.textStyle ?? Theme.of(context).textTheme.button, + overflow: widget.textOverflow, ), ), ],