diff --git a/CHANGELOG.md b/CHANGELOG.md index 0187dab..f6117fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,3 +53,7 @@ Update flags dimension to reduce application size ## 1.0.4 Update country name with translated version + +## 1.1.0 + +Changed CElement with CountryCode and fix error on favorite null \ No newline at end of file diff --git a/README.md b/README.md index 6a36675..ea945ba 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Pub](https://img.shields.io/badge/Pub-1.0.4-orange.svg)](https://pub.dartlang.org/packages/country_code_picker) +[![Pub](https://img.shields.io/badge/Pub-1.1.0-orange.svg)](https://pub.dartlang.org/packages/country_code_picker) # country_code_picker @@ -22,22 +22,23 @@ Just put the component in your application setting the onChanged callback. initialSelection: 'IT', favorite: ['+39','FR'], ), - )); + ), + ); ``` Note: Your onChanged function can be any function of the type shown below: ```dart -(CElement)->dynamic +(CountryCode)->dynamic ``` Example: ```dart -void _onCountryChange(CElement cElement) { +void _onCountryChange(CountryCode countryCode) { //Todo : manipulate the selected country code here - print("New Country selected: " + cElement.toString()); + print("New Country selected: " + countryCode.toString()); } ``` diff --git a/lib/celement.dart b/lib/country_code.dart similarity index 69% rename from lib/celement.dart rename to lib/country_code.dart index 80ad905..cd9bdf0 100644 --- a/lib/celement.dart +++ b/lib/country_code.dart @@ -1,5 +1,10 @@ +mixin ToAlias {} + +@deprecated +class CElement = CountryCode with ToAlias; + /// Country element. This is the element that contains all the information -class CElement { +class CountryCode { /// the name of the country String name; @@ -12,7 +17,7 @@ class CElement { /// the dial code (+39,+93..) String dialCode; - CElement({this.name, this.flagUri, this.code, this.dialCode}); + CountryCode({this.name, this.flagUri, this.code, this.dialCode}); @override String toString() => "$dialCode"; diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 5801119..7937e9a 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -1,32 +1,33 @@ library country_code_picker; -import 'package:country_code_picker/celement.dart'; +import 'package:country_code_picker/country_code.dart'; import 'package:country_code_picker/country_codes.dart'; import 'package:country_code_picker/selection_dialog.dart'; import 'package:flutter/material.dart'; -export 'celement.dart'; +export 'country_code.dart'; class CountryCodePicker extends StatefulWidget { - final Function(CElement) onChanged; + final ValueChanged onChanged; final String initialSelection; final List favorite; final TextStyle textStyle; final EdgeInsetsGeometry padding; - CountryCodePicker( - {this.onChanged, - this.initialSelection, - this.favorite, - this.textStyle, - this.padding}); + CountryCodePicker({ + this.onChanged, + this.initialSelection, + this.favorite = const [], + this.textStyle, + this.padding = const EdgeInsets.all(0.0), + }); @override State createState() { List jsonList = codes; - List elements = jsonList - .map((s) => new CElement( + List elements = jsonList + .map((s) => new CountryCode( name: s['name'], code: s['code'], dialCode: s['dial_code'], @@ -39,9 +40,9 @@ class CountryCodePicker extends StatefulWidget { } class _CountryCodePickerState extends State { - CElement selectedItem; - List elements = []; - List favoriteElements = []; + CountryCode selectedItem; + List elements = []; + List favoriteElements = []; _CountryCodePickerState(this.elements); @@ -114,7 +115,7 @@ class _CountryCodePickerState extends State { }); } - void _publishSelection(CElement e) { + void _publishSelection(CountryCode e) { if (widget.onChanged != null) { widget.onChanged(e); } diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index a12ab51..32dd6a0 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -1,12 +1,12 @@ -import 'package:country_code_picker/celement.dart'; +import 'package:country_code_picker/country_code.dart'; import 'package:flutter/material.dart'; /// selection dialog used for selection of the country code class SelectionDialog extends StatefulWidget { - final List elements; + final List elements; /// elements passed as favorite - final List favoriteElements; + final List favoriteElements; SelectionDialog(this.elements, this.favoriteElements); @@ -16,7 +16,7 @@ class SelectionDialog extends StatefulWidget { class _SelectionDialogState extends State { /// this is useful for filtering purpose - List showedElements = []; + List showedElements = []; @override Widget build(BuildContext context) => new SimpleDialog( @@ -34,63 +34,70 @@ class _SelectionDialogState extends State { : new Column( crossAxisAlignment: CrossAxisAlignment.start, children: [] - ..addAll(widget.favoriteElements.map((f) { - return new SimpleDialogOption( - child: Flex( - direction: Axis.horizontal, - children: [ - Flexible( - child: Padding( - padding: const EdgeInsets.only(right: 16.0), - child: Image.asset( - f.flagUri, - package: 'country_code_picker', - width: 32.0, - ), + ..addAll(widget.favoriteElements + .map( + (f) => new SimpleDialogOption( + child: Flex( + direction: Axis.horizontal, + children: [ + Flexible( + child: Padding( + padding: + const EdgeInsets.only(right: 16.0), + child: Image.asset( + f.flagUri, + package: 'country_code_picker', + width: 32.0, + ), + ), + ), + Flexible( + fit: FlexFit.tight, + child: new Text( + f.toLongString(), + overflow: TextOverflow.fade, + ), + ), + ], ), + onPressed: () { + _selectItem(f); + }, ), - Flexible( - fit: FlexFit.tight, - child: new Text( - f.toLongString(), - overflow: TextOverflow.fade, - ), - ), - ], - ), - onPressed: () { - _selectItem(f); - }); - }).toList()) + ) + .toList()) ..add(new Divider())), ]..addAll(showedElements - .map((e) => new SimpleDialogOption( - key: Key(e.toLongString()), - child: Flex( - direction: Axis.horizontal, - children: [ - Flexible( - child: Padding( - padding: const EdgeInsets.only(right: 16.0), - child: Image.asset( - e.flagUri, - package: 'country_code_picker', - width: 32.0, + .map( + (e) => new SimpleDialogOption( + key: Key(e.toLongString()), + child: Flex( + direction: Axis.horizontal, + children: [ + Flexible( + child: Padding( + padding: const EdgeInsets.only(right: 16.0), + child: Image.asset( + e.flagUri, + package: 'country_code_picker', + width: 32.0, + ), + ), ), - ), + Flexible( + fit: FlexFit.tight, + child: Text( + e.toLongString(), + overflow: TextOverflow.fade, + ), + ), + ], ), - Flexible( - fit: FlexFit.tight, - child: Text( - e.toLongString(), - overflow: TextOverflow.fade, - ), - ), - ], - ), - onPressed: () { - _selectItem(e); - })) + onPressed: () { + _selectItem(e); + }, + ), + ) .toList())); @override @@ -111,7 +118,7 @@ class _SelectionDialogState extends State { }); } - void _selectItem(CElement e) { + void _selectItem(CountryCode e) { Navigator.pop(context, e); } } diff --git a/pubspec.yaml b/pubspec.yaml index 35b7f5d..789f793 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: country_code_picker description: A flutter package for showing a country code selector. -version: 1.0.4 +version: 1.1.0 author: Salvatore-Giordano homepage: https://github.com/Salvatore-Giordano/CountryCodePicker