Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions lib/country_code_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class CountryCodePicker extends StatefulWidget {
///Header Text Alignment
final MainAxisAlignment headerAlignment;

/// space after dropdown icon if shown
final double? spaceAfterDropdownIcon;

const CountryCodePicker({
this.onChanged,
this.onInit,
Expand Down Expand Up @@ -159,6 +162,7 @@ class CountryCodePicker extends StatefulWidget {
this.headerTextStyle = const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
this.hideHeaderText = false,
this.topBarPadding = const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20),
this.spaceAfterDropdownIcon,
Key? key,
}) : super(key: key);

Expand All @@ -177,9 +181,9 @@ class CountryCodePicker extends StatefulWidget {
final uppercaseCustomList = countryFilter!.map((criteria) => criteria.toUpperCase()).toList();
elements = elements
.where((criteria) =>
uppercaseCustomList.contains(criteria.code) ||
uppercaseCustomList.contains(criteria.name) ||
uppercaseCustomList.contains(criteria.dialCode))
uppercaseCustomList.contains(criteria.code) ||
uppercaseCustomList.contains(criteria.name) ||
uppercaseCustomList.contains(criteria.dialCode))
.toList();
}

Expand Down Expand Up @@ -207,8 +211,8 @@ class CountryCodePickerState extends State<CountryCodePicker> {
internalWidget = TextButton(
onPressed: widget.enabled
? pickerStyle == PickerStyle.dialog
? showCountryCodePickerDialog
: showCountryCodePickerBottomSheet
? showCountryCodePickerDialog
: showCountryCodePickerBottomSheet
: null,
child: Padding(
padding: widget.padding,
Expand Down Expand Up @@ -249,8 +253,8 @@ class CountryCodePickerState extends State<CountryCodePicker> {
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)),
? EdgeInsets.only(right: widget.spaceAfterDropdownIcon?? 16.0, left: 8.0)
: EdgeInsets.only(right: widget.spaceAfterDropdownIcon?? 16.0)),
child: Icon(
Icons.arrow_drop_down,
color: Colors.grey,
Expand Down Expand Up @@ -280,8 +284,8 @@ class CountryCodePickerState extends State<CountryCodePicker> {
if (oldWidget.initialSelection != widget.initialSelection) {
if (widget.initialSelection != null) {
selectedItem = elements.firstWhere(
(criteria) =>
(criteria.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
(criteria) =>
(criteria.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
(criteria.dialCode == widget.initialSelection) ||
(criteria.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
orElse: () => elements[0]);
Expand All @@ -298,8 +302,8 @@ class CountryCodePickerState extends State<CountryCodePicker> {

if (widget.initialSelection != null) {
selectedItem = elements.firstWhere(
(item) =>
(item.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
(item) =>
(item.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
(item.dialCode == widget.initialSelection) ||
(item.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
orElse: () => elements[0]);
Expand All @@ -309,11 +313,11 @@ class CountryCodePickerState extends State<CountryCodePicker> {

favoriteElements = elements
.where((item) =>
widget.favorite.firstWhereOrNull((criteria) =>
item.code!.toUpperCase() == criteria.toUpperCase() ||
item.dialCode == criteria ||
item.name!.toUpperCase() == criteria.toUpperCase()) !=
null)
widget.favorite.firstWhereOrNull((criteria) =>
item.code!.toUpperCase() == criteria.toUpperCase() ||
item.dialCode == criteria ||
item.name!.toUpperCase() == criteria.toUpperCase()) !=
null)
.toList();
}

Expand Down