diff --git a/example/pubspec.lock b/example/pubspec.lock index f910823..fa09b6c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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: @@ -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 @@ -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: @@ -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 @@ -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: @@ -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" diff --git a/lib/src/country_list_bottom_sheet.dart b/lib/src/country_list_bottom_sheet.dart index 6d3544f..ddc538b 100644 --- a/lib/src/country_list_bottom_sheet.dart +++ b/lib/src/country_list_bottom_sheet.dart @@ -10,6 +10,7 @@ void showCountryListBottomSheet({ VoidCallback? onClosed, List? favorite, List? exclude, + List? include, List? countryFilter, bool showPhoneCode = false, CountryListThemeData? countryListTheme, @@ -25,6 +26,7 @@ void showCountryListBottomSheet({ onSelect, favorite, exclude, + include, countryFilter, showPhoneCode, countryListTheme, @@ -41,6 +43,7 @@ Widget _builder( ValueChanged onSelect, List? favorite, List? exclude, + List? include, List? countryFilter, bool showPhoneCode, CountryListThemeData? countryListTheme, diff --git a/lib/src/country_list_view.dart b/lib/src/country_list_view.dart index c162bb2..ad91436 100644 --- a/lib/src/country_list_view.dart +++ b/lib/src/country_list_view.dart @@ -20,6 +20,11 @@ class CountryListView extends StatefulWidget { /// Note: Can't provide both [exclude] and [countryFilter] final List? 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? 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] @@ -43,6 +48,7 @@ class CountryListView extends StatefulWidget { Key? key, required this.onSelect, this.exclude, + this.include, this.favorite, this.countryFilter, this.showPhoneCode = false, @@ -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 @@ -94,6 +108,12 @@ class _CountryListViewState extends State { ); } + if (widget.include != null) { + _countryList.retainWhere( + (element) => widget.include!.contains(element.countryCode), + ); + } + if (widget.countryFilter != null) { _countryList.removeWhere( (element) => !widget.countryFilter!.contains(element.countryCode), diff --git a/pubspec.lock b/pubspec.lock index 3dac14f..20259ad 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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 @@ -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: @@ -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 @@ -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: @@ -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"