Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
Merge pull request #6 from Daniel-Ioannou/v1.0.6
  • Loading branch information
Daniel-Ioannou authored Sep 19, 2020
2 parents 64ea960 + 2cd0270 commit 5400d90
Show file tree
Hide file tree
Showing 14 changed files with 945 additions and 121 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## [1.1.0] - 19 Sep 2020

### Implement localization.
Add the `CountryLocalizations.delegate` in the list of your app delegates.
```Dart
MaterialApp(
supportedLocales: [
const Locale('en'),
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), // Generic Simplified Chinese 'zh_Hans'
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'), // Generic traditional Chinese 'zh_Hant'
],
localizationsDelegates: [
CountryLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
home: HomePage(),
);
```
### Supported languages:
* English
* Simplified Chinese
* Traditional Chinese

## [1.0.5] - 31 Aug 2020

* Update documentation.
Expand Down
20 changes: 19 additions & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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.5
country_picker: ^1.1.0
```
In your dart file, import the library:
Expand All @@ -30,6 +30,24 @@ showCountryPicker(
);
```

### For localization:
Add the `CountryLocalizations.delegate` in the list of your app delegates.
```Dart
MaterialApp(
supportedLocales: [
const Locale('en'),
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), // Generic Simplified Chinese 'zh_Hans'
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'), // Generic traditional Chinese 'zh_Hant'
],
localizationsDelegates: [
CountryLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
home: HomePage(),
);
```

### 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.
Expand Down
9 changes: 9 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:country_picker/country_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() => runApp(MyApp());

Expand All @@ -12,6 +13,14 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
supportedLocales: [
Locale('en'),
],
localizationsDelegates: [
CountryLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
home: HomePage(),
);
}
Expand Down
87 changes: 32 additions & 55 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,93 +1,91 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.4.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
collection:
clock:
dependency: transitive
description:
name: collection
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
version: "1.0.1"
collection:
dependency: transitive
description:
name: convert
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "1.14.13"
country_picker:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.0.5"
crypto:
version: "1.1.0"
fake_async:
dependency: transitive
description:
name: crypto
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "1.1.0"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
image:
intl:
dependency: transitive
description:
name: image
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
version: "0.16.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.8"
meta:
dependency: transitive
description:
Expand All @@ -101,21 +99,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
version: "1.7.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -134,7 +118,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.9.5"
stream_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -162,27 +146,20 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.15"
version: "0.2.17"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.2.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
sdks:
dart: ">=2.7.0 <3.0.0"
dart: ">=2.9.0-14.0.dev <3.0.0"
2 changes: 2 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies:
sdk: flutter
country_picker:
path: ../
flutter_localizations:
sdk: flutter

dev_dependencies:
flutter_test:
Expand Down
1 change: 1 addition & 0 deletions lib/country_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'src/country.dart';
import 'src/country_list_bottom_sheet.dart';

export 'src/country.dart';
export 'src/country_localizations.dart';

/// Shows a bottom sheet containing a list of countries to select one.
///
Expand Down
13 changes: 9 additions & 4 deletions lib/src/country.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ class Country {
final String fullExampleWithPlusSign;

///Country name (country code)
final String displayNameNoE164Cc;
final String displayNameNoCountryCode;
final String e164Key;

@Deprecated('The modern term is displayNameNoCountryCode. '
'This feature was deprecated after v1.0.6.')
String get displayNameNoE164Cc => displayNameNoCountryCode;

Country({
this.phoneCode,
this.countryCode,
Expand All @@ -36,7 +41,7 @@ class Country {
this.example,
this.displayName,
this.fullExampleWithPlusSign,
this.displayNameNoE164Cc,
this.displayNameNoCountryCode,
this.e164Key,
});

Expand All @@ -50,7 +55,7 @@ class Country {
example = json['example'] as String,
displayName = json['display_name'] as String,
fullExampleWithPlusSign = json['full_example_with_plus_sign'] as String,
displayNameNoE164Cc = json['display_name_no_e164_cc'] as String,
displayNameNoCountryCode = json['display_name_no_e164_cc'] as String,
e164Key = json['e164_key'] as String;

Map<String, dynamic> toJson() {
Expand All @@ -64,7 +69,7 @@ class Country {
data['example'] = example;
data['display_name'] = displayName;
data['full_example_with_plus_sign'] = fullExampleWithPlusSign;
data['display_name_no_e164_cc'] = displayNameNoE164Cc;
data['display_name_no_e164_cc'] = displayNameNoCountryCode;
data['e164_key'] = e164Key;
return data;
}
Expand Down
8 changes: 6 additions & 2 deletions lib/src/country_list_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:country_picker/country_picker.dart';
import 'package:country_picker/src/utils.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -37,6 +38,7 @@ class _CountryListViewState extends State<CountryListView> {
void initState() {
super.initState();
_searchController = TextEditingController();

_countryList =
countryCodes.map((country) => Country.from(json: country)).toList();

Expand All @@ -61,7 +63,7 @@ class _CountryListViewState extends State<CountryListView> {
decoration: InputDecoration(
labelText: "Search",
hintText: "Search",
prefixIcon: Icon(Icons.search),
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderSide: BorderSide(
color: const Color(0xFF8C98A8).withOpacity(0.2),
Expand Down Expand Up @@ -115,7 +117,9 @@ class _CountryListViewState extends State<CountryListView> {
const SizedBox(width: 15),
Expanded(
child: Text(
country.name,
CountryLocalizations.of(context)
?.countryName(countryCode: country.countryCode) ??
country.name,
style: const TextStyle(fontSize: 16),
),
)
Expand Down
Loading

0 comments on commit 5400d90

Please sign in to comment.