add comparator
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 1.3.5
|
||||||
|
|
||||||
|
- Add `comparator` property
|
||||||
|
|
||||||
## 1.3.4
|
## 1.3.4
|
||||||
|
|
||||||
- Add `showFlagDialog` and `showFlagMain`
|
- Add `showFlagDialog` and `showFlagMain`
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
favorite: ['+39', 'FR'],
|
favorite: ['+39', 'FR'],
|
||||||
showFlag: false,
|
showFlag: false,
|
||||||
showFlagDialog: true,
|
showFlagDialog: true,
|
||||||
|
comparator: (a, b) => b.name.compareTo(a.name),
|
||||||
//Get the country information relevant to the initial selection
|
//Get the country information relevant to the initial selection
|
||||||
onInit: (code) => print("${code.name} ${code.dialCode}"),
|
onInit: (code) => print("${code.name} ${code.dialCode}"),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ class CountryCodePicker extends StatefulWidget {
|
|||||||
/// Width of the flag images
|
/// Width of the flag images
|
||||||
final double flagWidth;
|
final double flagWidth;
|
||||||
|
|
||||||
|
/// Use this property to change the order of the options
|
||||||
|
final Comparator<CountryCode> comparator;
|
||||||
|
|
||||||
CountryCodePicker({
|
CountryCodePicker({
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.onInit,
|
this.onInit,
|
||||||
@@ -66,6 +69,7 @@ class CountryCodePicker extends StatefulWidget {
|
|||||||
this.flagWidth = 32.0,
|
this.flagWidth = 32.0,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
this.textOverflow = TextOverflow.ellipsis,
|
this.textOverflow = TextOverflow.ellipsis,
|
||||||
|
this.comparator,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -75,6 +79,10 @@ class CountryCodePicker extends StatefulWidget {
|
|||||||
List<CountryCode> elements =
|
List<CountryCode> elements =
|
||||||
jsonList.map((json) => CountryCode.fromJson(json)).toList();
|
jsonList.map((json) => CountryCode.fromJson(json)).toList();
|
||||||
|
|
||||||
|
if (comparator != null) {
|
||||||
|
elements.sort(comparator);
|
||||||
|
}
|
||||||
|
|
||||||
if (countryFilter.length > 0) {
|
if (countryFilter.length > 0) {
|
||||||
elements = elements.where((c) => countryFilter.contains(c.code)).toList();
|
elements = elements.where((c) => countryFilter.contains(c.code)).toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: country_code_picker
|
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
|
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
|
homepage: https://github.com/Salvatore-Giordano/CountryCodePicker
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
Reference in New Issue
Block a user