From f5b138e557f9e2a2121778c223d594190a8063ae Mon Sep 17 00:00:00 2001 From: -Daniel Ioannou Date: Sat, 22 Aug 2020 23:20:40 +0300 Subject: [PATCH 1/3] Implement show phone code option --- example/lib/main.dart | 1 + example/pubspec.lock | 2 +- lib/country_picker.dart | 4 ++++ lib/src/country_list_bottom_sheet.dart | 10 +++++++-- lib/src/country_list_view.dart | 30 +++++++++++++++++++++----- pubspec.yaml | 2 +- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index dbe7c96..4a1cfd0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -32,6 +32,7 @@ class HomePage extends StatelessWidget { showCountryPicker( context: context, exclude: ['KN', 'MF'], + showPhoneCode: true, onSelect: (Country country) { print('Select country: ${country.displayName}'); }, diff --git a/example/pubspec.lock b/example/pubspec.lock index 27ec08f..6dbb58d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -56,7 +56,7 @@ packages: path: ".." relative: true source: path - version: "1.0.2" + version: "1.0.3" crypto: dependency: transitive description: diff --git a/lib/country_picker.dart b/lib/country_picker.dart index 38f36d4..e7818c2 100644 --- a/lib/country_picker.dart +++ b/lib/country_picker.dart @@ -16,6 +16,8 @@ export 'src/country.dart'; /// An optional [exclude] argument can be used to exclude(remove) one ore more /// country from the countries list. It takes a list of country code(iso2). /// +/// An optional [showPhoneCode] argument can be used to show phone code. +/// /// The `context` argument is used to look up the [Scaffold] for the bottom /// sheet. It is only used when the method is called. Its corresponding widget /// can be safely removed from the tree before the bottom sheet is closed. @@ -23,6 +25,7 @@ void showCountryPicker({ @required BuildContext context, @required ValueChanged onSelect, List exclude, + bool showPhoneCode = false, }) { assert(context != null); assert(onSelect != null); @@ -30,5 +33,6 @@ void showCountryPicker({ context: context, onSelect: onSelect, exclude: exclude, + showPhoneCode: showPhoneCode, ); } diff --git a/lib/src/country_list_bottom_sheet.dart b/lib/src/country_list_bottom_sheet.dart index c906066..6a29ae0 100644 --- a/lib/src/country_list_bottom_sheet.dart +++ b/lib/src/country_list_bottom_sheet.dart @@ -7,6 +7,7 @@ void showCountryListBottomSheet({ @required BuildContext context, @required ValueChanged onSelect, List exclude, + bool showPhoneCode = false, }) { assert(context != null); assert(onSelect != null); @@ -14,7 +15,7 @@ void showCountryListBottomSheet({ context: context, isScrollControlled: true, backgroundColor: Colors.transparent, - builder: (_) => _builder(context, onSelect, exclude), + builder: (_) => _builder(context, onSelect, exclude, showPhoneCode), ); } @@ -22,6 +23,7 @@ Widget _builder( BuildContext context, ValueChanged onSelect, List exclude, + bool showPhoneCode, ) { final device = MediaQuery.of(context).size.height; final statusBarHeight = MediaQuery.of(context).padding.top; @@ -45,6 +47,10 @@ Widget _builder( topRight: Radius.circular(40.0), ), ), - child: CountryListView(onSelect: onSelect, exclude: exclude), + child: CountryListView( + onSelect: onSelect, + exclude: exclude, + showPhoneCode: showPhoneCode, + ), ); } diff --git a/lib/src/country_list_view.dart b/lib/src/country_list_view.dart index a2ecf25..556f66b 100644 --- a/lib/src/country_list_view.dart +++ b/lib/src/country_list_view.dart @@ -5,15 +5,24 @@ import 'country.dart'; import 'res/country_codes.dart'; class CountryListView extends StatefulWidget { - final List exclude; - /// Called when a country is select. /// /// The country picker passes the new value to the callback. final ValueChanged onSelect; - const CountryListView({Key key, @required this.onSelect, this.exclude}) - : assert(onSelect != null), + /// An optional [showPhoneCode] argument can be used to show phone code. + final bool showPhoneCode; + + /// An optional [exclude] argument can be used to exclude(remove) one ore more + /// country from the countries list. It takes a list of country code(iso2). + final List exclude; + + const CountryListView({ + Key key, + @required this.onSelect, + this.exclude, + this.showPhoneCode = false, + }) : assert(onSelect != null), super(key: key); @override @@ -61,7 +70,18 @@ class _CountryListViewState extends State { Utils.countryCodeToEmoji(country.countryCode), style: const TextStyle(fontSize: 25), ), - const SizedBox(width: 15), + if (widget.showPhoneCode) ...[ + const SizedBox(width: 15), + Container( + width: 45, + child: Text( + '+${country.phoneCode}', + style: const TextStyle(fontSize: 16), + ), + ), + const SizedBox(width: 5), + ] else + const SizedBox(width: 15), Expanded( child: Text( country.name, diff --git a/pubspec.yaml b/pubspec.yaml index 4b7a21b..072bab7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: country_picker description: A flutter package to select a country from a list of countries. -version: 1.0.2 +version: 1.0.3 homepage: https://github.com/Daniel-Ioannou repository: https://github.com/Daniel-Ioannou/flutter_country_picker From d40e64956f4cfe366dbec8f2ca605d68b4e1b465 Mon Sep 17 00:00:00 2001 From: Daniel Ioannou Date: Sat, 22 Aug 2020 23:23:20 +0300 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d40ff47..80e0b1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.0.3] - 22 Aug 2020 + +* Add show phone code option. ## [1.0.2] - 18 Aug 2020 From 95f5673a50fd5d94eaf268d2c56f5b9fe238dd34 Mon Sep 17 00:00:00 2001 From: Daniel Ioannou Date: Sat, 22 Aug 2020 23:26:05 +0300 Subject: [PATCH 3/3] Update README.md --- README.md | 4 +++- example/lib/main.dart | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c44afa..de1e351 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A flutter package to select a country from a list of countries. Add the package to your pubspec.yaml: ```yaml - country_picker: ^1.0.2 + country_picker: ^1.0.3 ``` In your dart file, import the library: @@ -21,6 +21,7 @@ A flutter package to select a country from a list of countries. ```Dart showCountryPicker( context: context, + showPhoneCode: true, // optional. Shows phone code before the country name. onSelect: (Country country) { print('Select country: ${country.displayName}'); }, @@ -29,6 +30,7 @@ showCountryPicker( ### Parameters: * `onSelect`: Called when a country is select. The country picker passes the new value to the callback (required) +* `showPhoneCode`: Can be used to to show phone code before the country name. * `exclude`: Can be used to exclude(remove) one ore more country from the countries list (optional). ```Dart showCountryPicker( diff --git a/example/lib/main.dart b/example/lib/main.dart index 4a1cfd0..bb8aed2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -31,7 +31,9 @@ class HomePage extends StatelessWidget { onPressed: () { showCountryPicker( context: context, + //Optional. Can be used to exclude(remove) one ore more country from the countries list (optional). exclude: ['KN', 'MF'], + //Optional. Shows phone code before the country name. showPhoneCode: true, onSelect: (Country country) { print('Select country: ${country.displayName}');