diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index d9ea707..6016fe6 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -68,6 +68,9 @@ class CountryCodePicker extends StatefulWidget { /// Set to true if you want to hide the search part final bool hideSearch; + /// Set to true if you want to show drop down button + final bool showDropDownButton; + CountryCodePicker({ this.onChanged, this.onInit, @@ -96,6 +99,7 @@ class CountryCodePicker extends StatefulWidget { this.comparator, this.countryFilter, this.hideSearch = false, + this.showDropDownButton = false, this.dialogSize, this.closeIcon = const Icon(Icons.close), Key key, @@ -106,7 +110,7 @@ class CountryCodePicker extends StatefulWidget { List jsonList = codes; List elements = - jsonList.map((json) => CountryCode.fromJson(json)).toList(); + jsonList.map((json) => CountryCode.fromJson(json)).toList(); if (comparator != null) { elements.sort(comparator); @@ -114,12 +118,12 @@ class CountryCodePicker extends StatefulWidget { if (countryFilter != null && countryFilter.isNotEmpty) { final uppercaseCustomList = - countryFilter.map((c) => c.toUpperCase()).toList(); + countryFilter.map((c) => c.toUpperCase()).toList(); elements = elements .where((c) => - uppercaseCustomList.contains(c.code) || - uppercaseCustomList.contains(c.name) || - uppercaseCustomList.contains(c.dialCode)) + uppercaseCustomList.contains(c.code) || + uppercaseCustomList.contains(c.name) || + uppercaseCustomList.contains(c.dialCode)) .toList(); } @@ -150,6 +154,7 @@ class CountryCodePickerState extends State { direction: Axis.horizontal, mainAxisSize: MainAxisSize.min, children: [ + if (widget.showFlagMain != null ? widget.showFlagMain : widget.showFlag) @@ -167,6 +172,7 @@ class CountryCodePickerState extends State { ), ), ), + if (!widget.hideMainText) Flexible( fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, @@ -174,10 +180,25 @@ class CountryCodePickerState extends State { widget.showOnlyCountryWhenClosed ? selectedItem.toCountryStringOnly() : selectedItem.toString(), - style: widget.textStyle ?? Theme.of(context).textTheme.button, + style: widget.textStyle ?? Theme + .of(context) + .textTheme + .button, overflow: widget.textOverflow, ), ), + if(widget.showDropDownButton) + 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: Icon(Icons.arrow_drop_down, color: Colors.grey, + size: widget.flagWidth,) + ), + ), ], ), ); @@ -200,9 +221,9 @@ class CountryCodePickerState extends State { if (oldWidget.initialSelection != widget.initialSelection) { if (widget.initialSelection != null) { selectedItem = elements.firstWhere( - (e) => - (e.code.toUpperCase() == - widget.initialSelection.toUpperCase()) || + (e) => + (e.code.toUpperCase() == + widget.initialSelection.toUpperCase()) || (e.dialCode == widget.initialSelection) || (e.name.toUpperCase() == widget.initialSelection.toUpperCase()), orElse: () => elements[0]); @@ -219,8 +240,8 @@ class CountryCodePickerState extends State { if (widget.initialSelection != null) { selectedItem = elements.firstWhere( - (e) => - (e.code.toUpperCase() == widget.initialSelection.toUpperCase()) || + (e) => + (e.code.toUpperCase() == widget.initialSelection.toUpperCase()) || (e.dialCode == widget.initialSelection) || (e.name.toUpperCase() == widget.initialSelection.toUpperCase()), orElse: () => elements[0]); @@ -230,13 +251,13 @@ class CountryCodePickerState extends State { favoriteElements = elements .where((e) => - widget.favorite.firstWhere( - (f) => - e.code.toUpperCase() == f.toUpperCase() || - e.dialCode == f || - e.name.toUpperCase() == f.toUpperCase(), - orElse: () => null) != - null) + widget.favorite.firstWhere( + (f) => + e.code.toUpperCase() == f.toUpperCase() || + e.dialCode == f || + e.name.toUpperCase() == f.toUpperCase(), + orElse: () => null) != + null) .toList(); } @@ -245,25 +266,26 @@ class CountryCodePickerState extends State { barrierColor: widget.barrierColor ?? Colors.grey.withOpacity(0.5), backgroundColor: widget.backgroundColor ?? Colors.transparent, context: context, - builder: (context) => Center( - child: SelectionDialog( - elements, - favoriteElements, - showCountryOnly: widget.showCountryOnly, - emptySearchBuilder: widget.emptySearchBuilder, - searchDecoration: widget.searchDecoration, - searchStyle: widget.searchStyle, - textStyle: widget.dialogTextStyle, - boxDecoration: widget.boxDecoration, - showFlag: widget.showFlagDialog != null - ? widget.showFlagDialog - : widget.showFlag, - flagWidth: widget.flagWidth, - size: widget.dialogSize, - hideSearch: widget.hideSearch, - closeIcon: widget.closeIcon, - ), - ), + builder: (context) => + Center( + child: SelectionDialog( + elements, + favoriteElements, + showCountryOnly: widget.showCountryOnly, + emptySearchBuilder: widget.emptySearchBuilder, + searchDecoration: widget.searchDecoration, + searchStyle: widget.searchStyle, + textStyle: widget.dialogTextStyle, + boxDecoration: widget.boxDecoration, + showFlag: widget.showFlagDialog != null + ? widget.showFlagDialog + : widget.showFlag, + flagWidth: widget.flagWidth, + size: widget.dialogSize, + hideSearch: widget.hideSearch, + closeIcon: widget.closeIcon, + ), + ), ).then((e) { if (e != null) { setState(() {