add comparator

This commit is contained in:
Salvatore Giordano
2020-03-09 00:07:28 +01:00
parent 9af6647f1a
commit 1936cbb6ad
4 changed files with 14 additions and 1 deletions

View File

@@ -45,6 +45,9 @@ class CountryCodePicker extends StatefulWidget {
/// Width of the flag images
final double flagWidth;
/// Use this property to change the order of the options
final Comparator<CountryCode> comparator;
CountryCodePicker({
this.onChanged,
this.onInit,
@@ -66,6 +69,7 @@ class CountryCodePicker extends StatefulWidget {
this.flagWidth = 32.0,
this.enabled = true,
this.textOverflow = TextOverflow.ellipsis,
this.comparator,
});
@override
@@ -75,6 +79,10 @@ class CountryCodePicker extends StatefulWidget {
List<CountryCode> elements =
jsonList.map((json) => CountryCode.fromJson(json)).toList();
if (comparator != null) {
elements.sort(comparator);
}
if (countryFilter.length > 0) {
elements = elements.where((c) => countryFilter.contains(c.code)).toList();
}