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

@@ -1,3 +1,7 @@
## 1.3.5
- Add `comparator` property
## 1.3.4
- Add `showFlagDialog` and `showFlagMain`

View File

@@ -44,6 +44,7 @@ class _MyAppState extends State<MyApp> {
favorite: ['+39', 'FR'],
showFlag: false,
showFlagDialog: true,
comparator: (a, b) => b.name.compareTo(a.name),
//Get the country information relevant to the initial selection
onInit: (code) => print("${code.name} ${code.dialCode}"),
),

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();
}

View File

@@ -1,6 +1,6 @@
name: country_code_picker
description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox
version: 1.3.4
version: 1.3.5
homepage: https://github.com/Salvatore-Giordano/CountryCodePicker
environment: