Merge pull request #20 from herovickers/feature/show-only-countries

Feature: Option To Show Only Countries In Dialog
This commit is contained in:
Salvatore Giordano
2019-03-26 09:46:42 +01:00
committed by GitHub
3 changed files with 15 additions and 4 deletions

View File

@@ -23,4 +23,6 @@ class CountryCode {
String toString() => "$dialCode"; String toString() => "$dialCode";
String toLongString() => "$dialCode $name"; String toLongString() => "$dialCode $name";
String toCountryStringOnly() => '$name';
} }

View File

@@ -1,3 +1,4 @@
library country_code_picker; library country_code_picker;
import 'package:country_code_picker/country_code.dart'; import 'package:country_code_picker/country_code.dart';
@@ -13,6 +14,7 @@ class CountryCodePicker extends StatefulWidget {
final List<String> favorite; final List<String> favorite;
final TextStyle textStyle; final TextStyle textStyle;
final EdgeInsetsGeometry padding; final EdgeInsetsGeometry padding;
final bool showCountryOnly;
CountryCodePicker({ CountryCodePicker({
this.onChanged, this.onChanged,
@@ -20,6 +22,7 @@ class CountryCodePicker extends StatefulWidget {
this.favorite = const [], this.favorite = const [],
this.textStyle, this.textStyle,
this.padding = const EdgeInsets.all(0.0), this.padding = const EdgeInsets.all(0.0),
this.showCountryOnly = false,
}); });
@override @override
@@ -103,7 +106,7 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
void _showSelectionDialog() { void _showSelectionDialog() {
showDialog( showDialog(
context: context, context: context,
builder: (_) => new SelectionDialog(elements, favoriteElements), builder: (_) => new SelectionDialog(elements, favoriteElements, showCountryOnly: widget.showCountryOnly),
).then((e) { ).then((e) {
if (e != null) { if (e != null) {
setState(() { setState(() {

View File

@@ -4,11 +4,13 @@ import 'package:flutter/material.dart';
/// selection dialog used for selection of the country code /// selection dialog used for selection of the country code
class SelectionDialog extends StatefulWidget { class SelectionDialog extends StatefulWidget {
final List<CountryCode> elements; final List<CountryCode> elements;
bool showCountryOnly;
/// elements passed as favorite /// elements passed as favorite
final List<CountryCode> favoriteElements; final List<CountryCode> favoriteElements;
SelectionDialog(this.elements, this.favoriteElements); SelectionDialog(this.elements, this.favoriteElements,
{this.showCountryOnly});
@override @override
State<StatefulWidget> createState() => new _SelectionDialogState(); State<StatefulWidget> createState() => new _SelectionDialogState();
@@ -54,7 +56,9 @@ class _SelectionDialogState extends State<SelectionDialog> {
Flexible( Flexible(
fit: FlexFit.tight, fit: FlexFit.tight,
child: new Text( child: new Text(
f.toLongString(), widget.showCountryOnly
? f.toCountryStringOnly()
: f.toLongString(),
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
), ),
), ),
@@ -87,7 +91,9 @@ class _SelectionDialogState extends State<SelectionDialog> {
Flexible( Flexible(
fit: FlexFit.tight, fit: FlexFit.tight,
child: Text( child: Text(
e.toLongString(), widget.showCountryOnly
? e.toCountryStringOnly()
: e.toLongString(),
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
), ),
), ),