diff --git a/example/lib/main.dart b/example/lib/main.dart index 6e628a2..c65f5d5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -43,6 +43,7 @@ class _MyAppState extends State { initialSelection: 'IT', favorite: ['+39', 'FR'], showFlag: false, + customList: ['IT', 'FR'], showFlagDialog: true, comparator: (a, b) => b.name.compareTo(a.name), //Get the country information relevant to the initial selection diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index a7b63f1..e026b3c 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -21,6 +21,7 @@ class CountryCodePicker extends StatefulWidget { final Function(CountryCode) builder; final bool enabled; final TextOverflow textOverflow; + final List customList; /// shows the name of the country instead of the dialcode final bool showOnlyCountryWhenClosed; @@ -70,6 +71,7 @@ class CountryCodePicker extends StatefulWidget { this.enabled = true, this.textOverflow = TextOverflow.ellipsis, this.comparator, + this.customList, }); @override @@ -83,6 +85,15 @@ class CountryCodePicker extends StatefulWidget { elements.sort(comparator); } + if (customList != null) { + elements = elements + .where((c) => + customList.contains(c.code) || + customList.contains(c.name) || + customList.contains(c.dialCode)) + .toList(); + } + if (countryFilter.length > 0) { elements = elements.where((c) => countryFilter.contains(c.code)).toList(); }