Merge pull request #5 from Salvatore-Giordano/feature/4-return-whole-celement
Refs #4: onChanged has a full CElement as argument and not only a string
This commit is contained in:
@@ -21,3 +21,7 @@ Favorite and initial selection can be one of code or dial code
|
||||
## 0.1.3
|
||||
|
||||
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)
|
||||
@@ -1,4 +1,4 @@
|
||||
[](https://pub.dartlang.org/packages/country_code_picker)
|
||||
[](https://pub.dartlang.org/packages/country_code_picker)
|
||||
|
||||
# country_code_picker
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
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/country_codes.dart';
|
||||
import 'package:country_code_picker/selection_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CountryCodePicker extends StatefulWidget {
|
||||
final Function(String) onChanged;
|
||||
final Function(CElement) onChanged;
|
||||
final String initialSelection;
|
||||
final List<String> favorite;
|
||||
|
||||
@@ -45,8 +45,9 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
|
||||
initState() {
|
||||
if (widget.initialSelection != null) {
|
||||
selectedItem = elements.firstWhere(
|
||||
(e) => (e.code.toUpperCase() == widget.initialSelection.toUpperCase()) ||
|
||||
(e.dialCode == widget.initialSelection.toString()),
|
||||
(e) =>
|
||||
(e.code.toUpperCase() == widget.initialSelection.toUpperCase()) ||
|
||||
(e.dialCode == widget.initialSelection.toString()),
|
||||
orElse: () => elements[0]);
|
||||
} else {
|
||||
selectedItem = elements[0];
|
||||
@@ -54,12 +55,10 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
|
||||
|
||||
favoriteElements = elements
|
||||
.where((e) =>
|
||||
widget.favorite.firstWhere(
|
||||
(f) => e.code == f.toUpperCase() || e.dialCode == f.toString(),
|
||||
orElse: () => null) !=
|
||||
widget.favorite
|
||||
.firstWhere((f) => e.code == f.toUpperCase() || e.dialCode == f.toString(), orElse: () => null) !=
|
||||
null)
|
||||
.toList();
|
||||
print(favoriteElements);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -72,8 +71,9 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
|
||||
setState(() {
|
||||
selectedItem = e;
|
||||
});
|
||||
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged(e.dialCode);
|
||||
widget.onChanged(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: country_code_picker
|
||||
description: A flutter package for showing a country code selector.
|
||||
version: 0.1.3
|
||||
version: 0.2.0
|
||||
author: Salvatore-Giordano <salvatoregiordanoo@gmail.com>
|
||||
homepage: https://github.com/Salvatore-Giordano/CountryCodePicker
|
||||
|
||||
@@ -9,7 +9,4 @@ environment:
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
dev_dependencies:
|
||||
test: ^0.12.0
|
||||
sdk: flutter
|
||||
Reference in New Issue
Block a user