Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'package:country_picker/country_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

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

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down Expand Up @@ -51,24 +53,24 @@ class MyApp extends StatelessWidget {
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: [
localizationsDelegates: const [
CountryLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
home: HomePage(),
home: const HomePage(),
);
}
}

class HomePage extends StatelessWidget {
HomePage({Key? key}) : super(key: key);
const HomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Demo for country picker')),
appBar: AppBar(title: const Text('Demo for country picker')),
body: Center(
child: ElevatedButton(
onPressed: () {
Expand All @@ -80,14 +82,14 @@ class HomePage extends StatelessWidget {
//Optional. Shows phone code before the country name.
showPhoneCode: true,
onSelect: (Country country) {
print('Select country: ${country.displayName}');
debugPrint('Select country: ${country.displayName}');
},
// Optional. Sheet moves when keyboard opens.
moveAlongWithKeyboard: false,
// Optional. Sets the theme for the country list picker.
countryListTheme: CountryListThemeData(
// Optional. Sets the border radius for the bottomsheet.
borderRadius: BorderRadius.only(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(40.0),
topRight: Radius.circular(40.0),
),
Expand All @@ -103,7 +105,7 @@ class HomePage extends StatelessWidget {
),
),
// Optional. Styles the text in the search field
searchTextStyle: TextStyle(
searchTextStyle: const TextStyle(
color: Colors.blue,
fontSize: 18,
),
Expand Down
8 changes: 8 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct main"
description:
name: flutter_lints
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
flutter_localizations:
dependency: "direct main"
description: flutter
Expand Down
2 changes: 2 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ dependencies:
path: ../
flutter_localizations:
sdk: flutter

flutter_lints: ^4.0.0

dev_dependencies:
flutter_test:
Expand Down
2 changes: 1 addition & 1 deletion example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:example/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
await tester.pumpWidget(const MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand Down
4 changes: 4 additions & 0 deletions lib/src/country_localizations.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:country_picker/src/res/strings/kz.dart';
import 'package:flutter/material.dart';

import 'res/strings/ar.dart';
Expand Down Expand Up @@ -139,6 +140,8 @@ class CountryLocalizations {
return da[countryCode];
case 'ca':
return ca[countryCode];
case 'kk':
return kz[countryCode];
case 'fa':
return fa[countryCode];
case 'en':
Expand Down Expand Up @@ -188,6 +191,7 @@ class _CountryLocalizationsDelegate
'id',
'cs',
'ca',
'kk',
'fa',
'da',
'ca',
Expand Down
4 changes: 4 additions & 0 deletions lib/src/country_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'res/strings/it.dart';
import 'res/strings/ja.dart';
import 'res/strings/ko.dart';
import 'res/strings/ku.dart';
import 'res/strings/kz.dart';
import 'res/strings/lt.dart';
import 'res/strings/lv.dart';
import 'res/strings/nb.dart';
Expand Down Expand Up @@ -290,6 +291,8 @@ class CountryParser {
return ca;
case 'he':
return he;
case 'kk':
return kz;
case 'fa':
return fa;
case 'en':
Expand Down Expand Up @@ -337,6 +340,7 @@ class CountryParser {
const Locale('da'),
const Locale('ca'),
const Locale('he'),
const Locale('kk'),
const Locale('fa'),
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'),
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'),
Expand Down
14 changes: 6 additions & 8 deletions lib/src/country_service.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import 'package:collection/collection.dart';
import 'package:country_picker/src/res/country_codes.dart';

import 'country.dart';
import 'res/country_codes.dart';

class CountryService {
final List<Country> _countries;

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

///Return list with all countries
List<Country> getAll() {
return _countries;
}

static final List<Map<String, dynamic>> getCountryCodes = countryCodes;

///Returns the first country that match the given code.
Country? findByCode(String? code) {
final uppercaseCode = code?.toUpperCase();
return _countries
.firstWhereOrNull((country) => country.countryCode == uppercaseCode);
return _countries.firstWhereOrNull((country) => country.countryCode == uppercaseCode);
}

///Returns the first country that match the given name.
Expand All @@ -35,8 +34,7 @@ class CountryService {

///Returns a list with all the countries that match the given codes list.
List<Country> findCountriesByCode(List<String> codes) {
final List<String> _codes =
codes.map((code) => code.toUpperCase()).toList();
final List<String> _codes = codes.map((code) => code.toUpperCase()).toList();
final List<Country> countries = [];
for (final code in _codes) {
final Country? country = findByCode(code);
Expand Down
Loading