Skip to content

Added an include field #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
23 changes: 8 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
country_picker:
dependency: "direct main"
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -92,7 +92,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -106,7 +106,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -118,7 +118,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -153,20 +153,13 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
3 changes: 3 additions & 0 deletions lib/src/country_list_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void showCountryListBottomSheet({
VoidCallback? onClosed,
List<String>? favorite,
List<String>? exclude,
List<String>? include,
List<String>? countryFilter,
bool showPhoneCode = false,
CountryListThemeData? countryListTheme,
Expand All @@ -25,6 +26,7 @@ void showCountryListBottomSheet({
onSelect,
favorite,
exclude,
include,
countryFilter,
showPhoneCode,
countryListTheme,
Expand All @@ -41,6 +43,7 @@ Widget _builder(
ValueChanged<Country> onSelect,
List<String>? favorite,
List<String>? exclude,
List<String>? include,
List<String>? countryFilter,
bool showPhoneCode,
CountryListThemeData? countryListTheme,
Expand Down
20 changes: 20 additions & 0 deletions lib/src/country_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class CountryListView extends StatefulWidget {
/// Note: Can't provide both [exclude] and [countryFilter]
final List<String>? exclude;

/// An options [include] argument can be used to include(add) one ore more
/// country from the countries list. It takes a list of country code(iso2).
/// Note: Can't provide both [include] and [exclude]
final List<String>? include;

/// An optional [countryFilter] argument can be used to filter the
/// list of countries. It takes a list of country code(iso2).
/// Note: Can't provide both [countryFilter] and [exclude]
Expand All @@ -43,6 +48,7 @@ class CountryListView extends StatefulWidget {
Key? key,
required this.onSelect,
this.exclude,
this.include,
this.favorite,
this.countryFilter,
this.showPhoneCode = false,
Expand All @@ -53,6 +59,14 @@ class CountryListView extends StatefulWidget {
exclude == null || countryFilter == null,
'Cannot provide both exclude and countryFilter',
),
assert(
include == null || exclude == null,
'Cannot provide both include and exclude',
),
assert(
include == null || countryFilter == null,
'Cannot provide both include and countryFilter',
),
super(key: key);

@override
Expand Down Expand Up @@ -94,6 +108,12 @@ class _CountryListViewState extends State<CountryListView> {
);
}

if (widget.include != null) {
_countryList.retainWhere(
(element) => widget.include!.contains(element.countryCode),
);
}

if (widget.countryFilter != null) {
_countryList.removeWhere(
(element) => !widget.countryFilter!.contains(element.countryCode),
Expand Down
23 changes: 8 additions & 15 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -80,7 +80,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -94,7 +94,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -106,7 +106,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -141,20 +141,13 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.15.0-7.0.dev <3.0.0"
dart: ">=2.17.0-0 <3.0.0"