From 51f95d1f5e06e8ac64bbe22e78f01a803656376c Mon Sep 17 00:00:00 2001 From: Alfredo Bautista <71638694+alfredo-handcash@users.noreply.github.com> Date: Thu, 13 May 2021 09:57:44 +0200 Subject: [PATCH] Feat/inject list countries (#1) * make list const to use in constructor * inject list of countryCodes --- lib/src/country_list_view.dart | 9 +++++++-- lib/src/res/country_codes.dart | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/src/country_list_view.dart b/lib/src/country_list_view.dart index d1ca3fb..915f586 100644 --- a/lib/src/country_list_view.dart +++ b/lib/src/country_list_view.dart @@ -28,6 +28,10 @@ class CountryListView extends StatefulWidget { /// country list bottom sheet. final CountryListThemeData? countryListTheme; + /// An optional argument for inject list of countries + /// with customized codes. + final List> countryList; + const CountryListView({ Key? key, required this.onSelect, @@ -35,6 +39,7 @@ class CountryListView extends StatefulWidget { this.countryFilter, this.showPhoneCode = false, this.countryListTheme, + this.countryList = countryCodes, }) : assert(exclude == null || countryFilter == null, 'Cannot provide both exclude and countryFilter'), super(key: key); @@ -53,7 +58,7 @@ class _CountryListViewState extends State { _searchController = TextEditingController(); _countryList = - countryCodes.map((country) => Country.from(json: country)).toList(); + widget.countryList.map((country) => Country.from(json: country)).toList(); //Remove duplicates country if not use phone code if (!widget.showPhoneCode) { @@ -178,5 +183,5 @@ class _CountryListViewState extends State { setState(() => _filteredList = _searchResult); } - get _defaultTextStyle => const TextStyle(fontSize: 16); + TextStyle get _defaultTextStyle => const TextStyle(fontSize: 16); } diff --git a/lib/src/res/country_codes.dart b/lib/src/res/country_codes.dart index 75e1d40..b0fb9a0 100644 --- a/lib/src/res/country_codes.dart +++ b/lib/src/res/country_codes.dart @@ -1,4 +1,4 @@ -final List> countryCodes = [ +const List> countryCodes = [ { "e164_cc": "93", "iso2_cc": "AF",