Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

exclude countries #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Here is a list of properties available to customize your widget:
|textOverflow| TextOverflow | the button text overflow behaviour |
|dialogSize| Size | the size of the selection dialog |
|countryFilter| List<String> | uses a list of strings to filter a sublist of countries |
|excludeCountries| List<String> | uses a list of strings to exclude a sublist of countries |
|showOnlyCountryWhenClosed| bool | if true it'll show only the country |
|alignLeft| bool | aligns the flag and the Text to the left |
|showFlag| bool | shows the flag everywhere |
Expand Down
18 changes: 18 additions & 0 deletions lib/country_code_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class CountryCodePicker extends StatefulWidget {
/// used to customize the country list
final List<String>? countryFilter;

/// used to exclude some countries
final List<String>? excludeCountries;

/// shows the name of the country instead of the dialcode
final bool showOnlyCountryWhenClosed;

Expand Down Expand Up @@ -112,6 +115,7 @@ class CountryCodePicker extends StatefulWidget {
this.boxDecoration,
this.comparator,
this.countryFilter,
this.excludeCountries,
this.hideSearch = false,
this.showDropDownButton = false,
this.dialogSize,
Expand Down Expand Up @@ -143,6 +147,20 @@ class CountryCodePicker extends StatefulWidget {
.toList();
}

if (excludeCountries != null && excludeCountries!.isNotEmpty) {
final uppercaseCustomList =
excludeCountries!.map((c) => c.toUpperCase()).toList();

final index = elements.indexWhere(((c) =>
uppercaseCustomList.contains(c.code) ||
uppercaseCustomList.contains(c.name) ||
uppercaseCustomList.contains(c.dialCode)));

if (index >= 0) {
elements.removeAt(index);
}
}

return CountryCodePickerState(elements);
}
}
Expand Down