diff --git a/example/lib/main.dart b/example/lib/main.dart index 37aaabe..ae3aed8 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -24,6 +24,7 @@ class _MyAppState extends State { body: new Center( child: new CountryCodePicker( onChanged: print, + showCountryOnly: true, // Initial selection and favorite can be one of code ('IT') OR dial_code('+39') initialSelection: 'IT', favorite: ['+39', 'FR']), diff --git a/lib/country_code.dart b/lib/country_code.dart index cd9bdf0..c289ff2 100644 --- a/lib/country_code.dart +++ b/lib/country_code.dart @@ -23,4 +23,6 @@ class CountryCode { String toString() => "$dialCode"; String toLongString() => "$dialCode $name"; + + String toCountryStringOnly() => '$name'; } diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 7937e9a..3a48ca0 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -1,3 +1,4 @@ + library country_code_picker; import 'package:country_code_picker/country_code.dart'; @@ -13,6 +14,7 @@ class CountryCodePicker extends StatefulWidget { final List favorite; final TextStyle textStyle; final EdgeInsetsGeometry padding; + final bool showCountryOnly; CountryCodePicker({ this.onChanged, @@ -20,6 +22,7 @@ class CountryCodePicker extends StatefulWidget { this.favorite = const [], this.textStyle, this.padding = const EdgeInsets.all(0.0), + this.showCountryOnly = false, }); @override @@ -103,7 +106,7 @@ class _CountryCodePickerState extends State { void _showSelectionDialog() { showDialog( context: context, - builder: (_) => new SelectionDialog(elements, favoriteElements), + builder: (_) => new SelectionDialog(elements, favoriteElements, showCountryOnly: widget.showCountryOnly), ).then((e) { if (e != null) { setState(() { diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index 32dd6a0..3b991fc 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -4,11 +4,13 @@ import 'package:flutter/material.dart'; /// selection dialog used for selection of the country code class SelectionDialog extends StatefulWidget { final List elements; + bool showCountryOnly; /// elements passed as favorite final List favoriteElements; - SelectionDialog(this.elements, this.favoriteElements); + SelectionDialog(this.elements, this.favoriteElements, + {this.showCountryOnly}); @override State createState() => new _SelectionDialogState(); @@ -54,7 +56,9 @@ class _SelectionDialogState extends State { Flexible( fit: FlexFit.tight, child: new Text( - f.toLongString(), + widget.showCountryOnly + ? f.toCountryStringOnly() + : f.toLongString(), overflow: TextOverflow.fade, ), ), @@ -87,7 +91,9 @@ class _SelectionDialogState extends State { Flexible( fit: FlexFit.tight, child: Text( - e.toLongString(), + widget.showCountryOnly + ? e.toCountryStringOnly() + : e.toLongString(), overflow: TextOverflow.fade, ), ),