v0.1.3: Favorite can be one of code or dial code

This commit is contained in:
Salvatore Giordano
2018-04-05 09:25:06 +02:00
parent 031a139334
commit a7e8a74c55
4 changed files with 14 additions and 11 deletions

View File

@@ -13,3 +13,7 @@ Removed flags in iOS because they show up weirdly.
## 0.1.1 ## 0.1.1
Tested with dart 2 Tested with dart 2
## 0.1.2
Favorite and initial selection can be one of code or dial code

View File

@@ -1,4 +1,4 @@
[![Pub](https://img.shields.io/badge/Pub-0.1.1-orange.svg)](https://pub.dartlang.org/packages/country_code_picker) [![Pub](https://img.shields.io/badge/Pub-0.1.2-orange.svg)](https://pub.dartlang.org/packages/country_code_picker)
# country_code_picker # country_code_picker
@@ -19,9 +19,9 @@ Just put the component in your application setting the onChanged callback.
body: new Center( body: new Center(
child: new CountryCodePicker( child: new CountryCodePicker(
onChanged: print, onChanged: print,
// Initial selection can be one of code ('IT') OR dial_code('+39') // Initial selection and favorite can be one of code ('IT') OR dial_code('+39')
initialSelection: 'IT', initialSelection: 'IT',
favorite: ['IT','FR'], favorite: ['+39','FR'],
), ),
)); ));

View File

@@ -44,19 +44,18 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
@override @override
initState() { initState() {
if (widget.initialSelection != null) { if (widget.initialSelection != null) {
selectedItem = elements.firstWhere( selectedItem = elements.firstWhere((e) {
(e) { e.code.toUpperCase() == widget.initialSelection.toUpperCase() ||
e.code.toUpperCase() == widget.initialSelection.toUpperCase() || e.dialCode == widget.initialSelection.toString();
e.dialCode == widget.initialSelection.toString(); }, orElse: () => elements[0]);
},
orElse: () => elements[0]);
} else { } else {
selectedItem = elements[0]; selectedItem = elements[0];
} }
favoriteElements = elements favoriteElements = elements
.where((e) => .where((e) =>
widget.favorite.firstWhere((f) => e.code == f.toUpperCase(), widget.favorite.firstWhere(
(f) => e.code == f.toUpperCase() || e.dialCode == f.toString(),
orElse: () => null) != orElse: () => null) !=
null) null)
.toList(); .toList();

View File

@@ -1,6 +1,6 @@
name: country_code_picker name: country_code_picker
description: A flutter package for showing a country code selector. description: A flutter package for showing a country code selector.
version: 0.1.1 version: 0.1.2
author: Salvatore-Giordano <salvatoregiordanoo@gmail.com> author: Salvatore-Giordano <salvatoregiordanoo@gmail.com>
homepage: https://github.com/Salvatore-Giordano/CountryCodePicker homepage: https://github.com/Salvatore-Giordano/CountryCodePicker