Refs #4: onChanged has a full CElement as argument and not only a string

This commit is contained in:
Salvatore Giordano
2018-05-05 11:12:33 +02:00
parent 209749036c
commit 712fd3ee25
3 changed files with 17 additions and 16 deletions

View File

@@ -21,3 +21,7 @@ Favorite and initial selection can be one of code or dial code
## 0.1.3 ## 0.1.3
Favorite and initial selection can be one of code or dial code Favorite and initial selection can be one of code or dial code
## 0.2.0
Now onChanged has a full CElement as argument and not only a string. (issue #4)

View File

@@ -1,12 +1,12 @@
library country_code_picker; library country_code_picker;
import 'package:country_code_picker/country_codes.dart';
import 'package:flutter/material.dart';
import 'package:country_code_picker/selection_dialog.dart';
import 'package:country_code_picker/celement.dart'; import 'package:country_code_picker/celement.dart';
import 'package:country_code_picker/country_codes.dart';
import 'package:country_code_picker/selection_dialog.dart';
import 'package:flutter/material.dart';
class CountryCodePicker extends StatefulWidget { class CountryCodePicker extends StatefulWidget {
final Function(String) onChanged; final Function(CElement) onChanged;
final String initialSelection; final String initialSelection;
final List<String> favorite; final List<String> favorite;
@@ -45,8 +45,9 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
initState() { initState() {
if (widget.initialSelection != null) { if (widget.initialSelection != null) {
selectedItem = elements.firstWhere( selectedItem = elements.firstWhere(
(e) => (e.code.toUpperCase() == widget.initialSelection.toUpperCase()) || (e) =>
(e.dialCode == widget.initialSelection.toString()), (e.code.toUpperCase() == widget.initialSelection.toUpperCase()) ||
(e.dialCode == widget.initialSelection.toString()),
orElse: () => elements[0]); orElse: () => elements[0]);
} else { } else {
selectedItem = elements[0]; selectedItem = elements[0];
@@ -54,12 +55,10 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
favoriteElements = elements favoriteElements = elements
.where((e) => .where((e) =>
widget.favorite.firstWhere( widget.favorite
(f) => e.code == f.toUpperCase() || e.dialCode == f.toString(), .firstWhere((f) => e.code == f.toUpperCase() || e.dialCode == f.toString(), orElse: () => null) !=
orElse: () => null) !=
null) null)
.toList(); .toList();
print(favoriteElements);
super.initState(); super.initState();
} }
@@ -72,8 +71,9 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
setState(() { setState(() {
selectedItem = e; selectedItem = e;
}); });
if (widget.onChanged != null) { if (widget.onChanged != null) {
widget.onChanged(e.dialCode); widget.onChanged(e);
} }
} }
}); });

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.3 version: 0.2.0
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
@@ -9,7 +9,4 @@ environment:
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
dev_dependencies:
test: ^0.12.0