Skip to content

Commit

Permalink
V1.0.3
Browse files Browse the repository at this point in the history
Merge pull request #3 from Daniel-Ioannou/v1.0.3
  • Loading branch information
Daniel-Ioannou authored Aug 22, 2020
2 parents 2195c5a + 95f5673 commit 79e23ad
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.0.3] - 22 Aug 2020

* Add show phone code option.

## [1.0.2] - 18 Aug 2020

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}');
},
Expand All @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ 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: <String>['KN', 'MF'],
//Optional. Shows phone code before the country name.
showPhoneCode: true,
onSelect: (Country country) {
print('Select country: ${country.displayName}');
},
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.2"
version: "1.0.3"
crypto:
dependency: transitive
description:
Expand Down
4 changes: 4 additions & 0 deletions lib/country_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ 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.
void showCountryPicker({
@required BuildContext context,
@required ValueChanged<Country> onSelect,
List<String> exclude,
bool showPhoneCode = false,
}) {
assert(context != null);
assert(onSelect != null);
showCountryListBottomSheet(
context: context,
onSelect: onSelect,
exclude: exclude,
showPhoneCode: showPhoneCode,
);
}
10 changes: 8 additions & 2 deletions lib/src/country_list_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ void showCountryListBottomSheet({
@required BuildContext context,
@required ValueChanged<Country> onSelect,
List<String> exclude,
bool showPhoneCode = false,
}) {
assert(context != null);
assert(onSelect != null);
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (_) => _builder(context, onSelect, exclude),
builder: (_) => _builder(context, onSelect, exclude, showPhoneCode),
);
}

Widget _builder(
BuildContext context,
ValueChanged<Country> onSelect,
List<String> exclude,
bool showPhoneCode,
) {
final device = MediaQuery.of(context).size.height;
final statusBarHeight = MediaQuery.of(context).padding.top;
Expand All @@ -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,
),
);
}
30 changes: 25 additions & 5 deletions lib/src/country_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ import 'country.dart';
import 'res/country_codes.dart';

class CountryListView extends StatefulWidget {
final List<String> exclude;

/// Called when a country is select.
///
/// The country picker passes the new value to the callback.
final ValueChanged<Country> 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<String> exclude;

const CountryListView({
Key key,
@required this.onSelect,
this.exclude,
this.showPhoneCode = false,
}) : assert(onSelect != null),
super(key: key);

@override
Expand Down Expand Up @@ -61,7 +70,18 @@ class _CountryListViewState extends State<CountryListView> {
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,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 79e23ad

Please sign in to comment.