Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72d10bcba5 | ||
|
|
0cc1771ebf | ||
|
|
864dce4d4b | ||
|
|
bc3cd989a4 | ||
|
|
f800e933ad | ||
|
|
c0a8a00d27 | ||
|
|
85f3ab6cf8 | ||
|
|
9b71ba2931 | ||
|
|
1344c6064e | ||
|
|
44945e23a5 | ||
|
|
e7896adbd8 | ||
|
|
84064c236d | ||
|
|
0a873bd7e9 | ||
|
|
84673f3488 | ||
|
|
0460f3f37c | ||
|
|
fbc4d9ea28 | ||
|
|
2078ad5506 | ||
|
|
4c64b01183 | ||
|
|
49143d8c97 | ||
|
|
9faf5a79cf | ||
|
|
282ed6e0be | ||
|
|
3bbd4e7e62 | ||
|
|
308f7b222c | ||
|
|
7f36d14ba6 | ||
|
|
24580fa79f | ||
|
|
e08260180d | ||
|
|
7055c0f485 | ||
|
|
f61a833a96 | ||
|
|
c127e4a882 | ||
|
|
08161e43b5 | ||
|
|
ca8312a6e5 | ||
|
|
6e6d7dc621 | ||
|
|
b279411802 | ||
|
|
5c10b16f16 | ||
|
|
24f5ae8ed3 | ||
|
|
102dd79324 | ||
|
|
a0ec0387bc | ||
|
|
cd063b34b6 | ||
|
|
82acd039de | ||
|
|
6a43ff1e5d | ||
|
|
df72607a43 | ||
|
|
416800385e | ||
|
|
077f37d99f | ||
|
|
a4ae3de55f | ||
|
|
b99060c4eb | ||
|
|
f754dc2d93 | ||
|
|
d67fa413a6 | ||
|
|
19db652adf | ||
|
|
4b87e67125 | ||
|
|
d9cf16a148 | ||
|
|
484a495360 | ||
|
|
b77740619a | ||
|
|
6ec226622b | ||
|
|
423400ec61 | ||
|
|
37582edcee | ||
|
|
6ed387285a | ||
|
|
4b86567052 | ||
|
|
684d0c2c7a | ||
|
|
6ee7de3511 | ||
|
|
3139f28604 | ||
|
|
d47c3a9308 | ||
|
|
7ac2a3d6e2 | ||
|
|
e9994c0eb1 | ||
|
|
32acbb11b2 |
36
.all-contributorsrc
Normal file
36
.all-contributorsrc
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"files": [
|
||||
"README.md"
|
||||
],
|
||||
"imageSize": 100,
|
||||
"commit": false,
|
||||
"commitConvention": "angular",
|
||||
"contributors": [
|
||||
{
|
||||
"login": "chandrabezzo",
|
||||
"name": "Chandra Abdul Fattah",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/16184998?v=4",
|
||||
"profile": "https://www.linkedin.com/in/chandra-abdul-fattah",
|
||||
"contributions": [
|
||||
"infra",
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "imtoori",
|
||||
"name": "Salvatore Giordano",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/20601437?v=4",
|
||||
"profile": "https://github.com/imtoori",
|
||||
"contributions": [
|
||||
"infra",
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
"skipCi": true,
|
||||
"repoType": "github",
|
||||
"repoHost": "https://github.com",
|
||||
"projectName": "CountryCodePicker",
|
||||
"projectOwner": "chandrabezzo"
|
||||
}
|
||||
25
.github/workflows/dart.yml
vendored
25
.github/workflows/dart.yml
vendored
@@ -1,20 +1,19 @@
|
||||
name: Publish plugin
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
|
||||
name: Publish to pub.dev
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
- '[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Publish
|
||||
uses: sakebook/actions-flutter-pub-publisher@v1.2.1
|
||||
with:
|
||||
credential: ${{ secrets.CREDENTIALS }}
|
||||
skip_test: true
|
||||
permissions:
|
||||
id-token: write # Required for authentication using OIDC
|
||||
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
|
||||
# with:
|
||||
# working-directory: path/to/package/within/repository
|
||||
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,10 +1,29 @@
|
||||
## 3.0.0 - March 10 2023
|
||||
## 3.4.0 - August 19 2025
|
||||
- Fix China translation
|
||||
- Adding flag autofocus
|
||||
|
||||
## 3.3.1 - August 19 2025
|
||||
- Fix French translation accent display issue
|
||||
- Correct French country name translations (Biélorussie, Koweït, Grenade, etc.)
|
||||
- Preserve accents in displayed names while maintaining search functionality
|
||||
- Update search logic to handle both accented and non-accented input
|
||||
|
||||
## 3.3.0 - March 26 2025
|
||||
- Fix localization, typo, and flag issue #51 thanks to @MrRoy121
|
||||
|
||||
## 3.2.0 - January 31 2025
|
||||
- Add country code picker style #6
|
||||
- Remove Special Character #37
|
||||
- Fixes for Flutter and Dart SDK Updates and Enhancements #44
|
||||
|
||||
## 3.1.0 - October 24 2024
|
||||
- Add some improvement
|
||||
|
||||
## 3.0.0 - March 10 2023
|
||||
- Support Flutter 3.7.0
|
||||
- Restructured package follow linter
|
||||
|
||||
## 2.0.2
|
||||
|
||||
- added localization for no_country text in italian and english (please open a pr with other languages if you know them 🙏)
|
||||
- added possibility to inject a custom list of countries using `CountryCodePicker.countryList`
|
||||
- minor fixes
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/build" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 24 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
39
README.md
39
README.md
@@ -1,4 +1,7 @@
|
||||

|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||

|
||||
[](https://pub.dartlang.org/packages/country_code_picker)
|
||||
[ LinkedIn](https://www.linkedin.com/in/salvatore-giordano/)
|
||||
@@ -56,6 +59,7 @@ void _onCountryChange(CountryCode countryCode) {
|
||||
|
||||
Just add the `CountryLocalizations.delegate` in the list of your app delegates
|
||||
|
||||
### Default Usage (Localization Enabled)
|
||||
```dart
|
||||
return new MaterialApp(
|
||||
supportedLocales: [
|
||||
@@ -137,9 +141,19 @@ Just add the `CountryLocalizations.delegate` in the list of your app delegates
|
||||
],
|
||||
```
|
||||
|
||||
### Force English (Localization Disabled)
|
||||
```dart
|
||||
return new MaterialApp(
|
||||
localizationsDelegates: [
|
||||
CountryLocalizations.delegate(enableLocalization: false),
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
```
|
||||
|
||||
## Customization
|
||||
|
||||
Here is a list of properties available to customize your widget:
|
||||
Here is a list of properties available to customizeccc your widget:
|
||||
|
||||
| Name | Type | Description |
|
||||
|-----|-----|------|
|
||||
@@ -183,3 +197,26 @@ as objectively and informative as possible so that we can understand your need a
|
||||
### Discussions and ideas
|
||||
We're happy to discuss and talk about ideas, post your
|
||||
question to [StackOverflow](https://stackoverflow.com/search?q=country+code+picker).
|
||||
## Contributors ✨
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- markdownlint-disable -->
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/chandra-abdul-fattah"><img src="https://avatars.githubusercontent.com/u/16184998?v=4?s=100" width="100px;" alt="Chandra Abdul Fattah"/><br /><sub><b>Chandra Abdul Fattah</b></sub></a><br /><a href="#infra-chandrabezzo" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/chandrabezzo/CountryCodePicker/commits?author=chandrabezzo" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/imtoori"><img src="https://avatars.githubusercontent.com/u/20601437?v=4?s=100" width="100px;" alt="Salvatore Giordano"/><br /><sub><b>Salvatore Giordano</b></sub></a><br /><a href="#infra-imtoori" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/chandrabezzo/CountryCodePicker/commits?author=imtoori" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/nilashish-roy-b8a4a0171/"><img src="https://avatars.githubusercontent.com/u/96123041?v=4?s=100" width="100px;" alt="Nilashish Roy"/><br /><sub><b>Nilashish Roy</b></sub></a><br /><a href="#infra-mrroy121" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/chandrabezzo/CountryCodePicker/commits?author=mrroy121" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-restore -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/packages" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/test/packages" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Flutter Plugins" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,71 +1,58 @@
|
||||
plugins {
|
||||
id "com.android.application"
|
||||
id "kotlin-android"
|
||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||
id "dev.flutter.flutter-gradle-plugin"
|
||||
}
|
||||
|
||||
def localProperties = new Properties()
|
||||
def localPropertiesFile = rootProject.file('local.properties')
|
||||
def localPropertiesFile = rootProject.file("local.properties")
|
||||
if (localPropertiesFile.exists()) {
|
||||
localPropertiesFile.withReader('UTF-8') { reader ->
|
||||
localPropertiesFile.withReader("UTF-8") { reader ->
|
||||
localProperties.load(reader)
|
||||
}
|
||||
}
|
||||
|
||||
def flutterRoot = localProperties.getProperty('flutter.sdk')
|
||||
if (flutterRoot == null) {
|
||||
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
|
||||
}
|
||||
|
||||
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
|
||||
def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
|
||||
if (flutterVersionCode == null) {
|
||||
flutterVersionCode = '1'
|
||||
flutterVersionCode = "1"
|
||||
}
|
||||
|
||||
def flutterVersionName = localProperties.getProperty('flutter.versionName')
|
||||
def flutterVersionName = localProperties.getProperty("flutter.versionName")
|
||||
if (flutterVersionName == null) {
|
||||
flutterVersionName = '1.0'
|
||||
flutterVersionName = "1.0"
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||
|
||||
android {
|
||||
compileSdkVersion flutter.compileSdkVersion
|
||||
ndkVersion flutter.ndkVersion
|
||||
namespace = "com.example.example"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
ndkVersion = flutter.ndkVersion
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "com.example.example"
|
||||
applicationId = "com.example.example"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
minSdk = flutter.minSdkVersion
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
versionCode = flutterVersionCode.toInteger()
|
||||
versionName = flutterVersionName
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.debug
|
||||
signingConfig = signingConfigs.debug
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flutter {
|
||||
source '../..'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
source = "../.."
|
||||
}
|
||||
|
||||
@@ -1,16 +1,3 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.7.10'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.2.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
@@ -18,14 +5,14 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.buildDir = '../build'
|
||||
rootProject.buildDir = "../build"
|
||||
subprojects {
|
||||
project.buildDir = "${rootProject.buildDir}/${project.name}"
|
||||
}
|
||||
subprojects {
|
||||
project.evaluationDependsOn(':app')
|
||||
project.evaluationDependsOn(":app")
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
tasks.register("clean", Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
include ':app'
|
||||
pluginManagement {
|
||||
def flutterSdkPath = {
|
||||
def properties = new Properties()
|
||||
file("local.properties").withInputStream { properties.load(it) }
|
||||
def flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
|
||||
return flutterSdkPath
|
||||
}()
|
||||
|
||||
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
|
||||
def properties = new Properties()
|
||||
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
|
||||
|
||||
assert localPropertiesFile.exists()
|
||||
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
def flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
|
||||
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
|
||||
plugins {
|
||||
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
||||
id "com.android.application" version "7.3.0" apply false
|
||||
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
|
||||
}
|
||||
|
||||
include ":app"
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
MyAppState createState() => MyAppState();
|
||||
@@ -89,6 +89,7 @@ class MyAppState extends State<MyApp> {
|
||||
],
|
||||
localizationsDelegates: const [
|
||||
CountryLocalizations.delegate,
|
||||
/// CountryLocalizations.getDelegate(enableLocalization: false), // For no localization only english just declare delegate this way.
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
@@ -104,15 +105,14 @@ class MyAppState extends State<MyApp> {
|
||||
onChanged: print,
|
||||
// Initial selection and favorite can be one of code ('IT') OR dial_code('+39')
|
||||
initialSelection: 'IT',
|
||||
favorite: const ['+39', 'FR'],
|
||||
countryFilter: const ['IT', 'FR'],
|
||||
showFlagDialog: false,
|
||||
comparator: (a, b) => b.name.compareTo(a.name),
|
||||
//You can set the margin between the flag and the country name to your taste.
|
||||
margin: const EdgeInsets.symmetric(horizontal: 6),
|
||||
comparator: (a, b) => b.name!.compareTo(a.name!),
|
||||
//Get the country information relevant to the initial selection
|
||||
onInit: (code) => debugPrint(
|
||||
"on init ${code.name} ${code.dialCode} ${code.name}"),
|
||||
onInit: (code) => debugPrint("on init ${code?.name} ${code?.dialCode} ${code?.name}"),
|
||||
),
|
||||
CountryCodePicker(
|
||||
hideHeaderText: true,
|
||||
onChanged: print,
|
||||
// Initial selection and favorite can be one of code ('IT') OR dial_code('+39')
|
||||
initialSelection: 'IT',
|
||||
@@ -122,6 +122,7 @@ class MyAppState extends State<MyApp> {
|
||||
flagDecoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
),
|
||||
pickerStyle: PickerStyle.bottomSheet,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 400,
|
||||
|
||||
@@ -11,7 +11,7 @@ version: 1.0.0+1
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ">=2.0.0-dev.68.0 <3.0.0"
|
||||
sdk: '>=2.17.0 <4.0.0'
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
|
||||
BIN
flags/sy.png
BIN
flags/sy.png
Binary file not shown.
|
Before Width: | Height: | Size: 494 B After Width: | Height: | Size: 2.4 KiB |
@@ -1,14 +0,0 @@
|
||||
// This is a generated file; do not edit or check into version control.
|
||||
FLUTTER_ROOT=/Users/bezzo/flutter
|
||||
FLUTTER_APPLICATION_PATH=/Users/bezzo/Desktop/CountryCodePicker
|
||||
COCOAPODS_PARALLEL_CODE_SIGN=true
|
||||
FLUTTER_TARGET=lib/main.dart
|
||||
FLUTTER_BUILD_DIR=build
|
||||
FLUTTER_BUILD_NAME=3.0.0
|
||||
FLUTTER_BUILD_NUMBER=3.0.0
|
||||
EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386
|
||||
EXCLUDED_ARCHS[sdk=iphoneos*]=armv7
|
||||
DART_OBFUSCATION=false
|
||||
TRACK_WIDGET_CREATION=true
|
||||
TREE_SHAKE_ICONS=false
|
||||
PACKAGE_CONFIG=.dart_tool/package_config.json
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This is a generated file; do not edit or check into version control.
|
||||
export "FLUTTER_ROOT=/Users/bezzo/flutter"
|
||||
export "FLUTTER_APPLICATION_PATH=/Users/bezzo/Desktop/CountryCodePicker"
|
||||
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
|
||||
export "FLUTTER_TARGET=lib/main.dart"
|
||||
export "FLUTTER_BUILD_DIR=build"
|
||||
export "FLUTTER_BUILD_NAME=3.0.0"
|
||||
export "FLUTTER_BUILD_NUMBER=3.0.0"
|
||||
export "DART_OBFUSCATION=false"
|
||||
export "TRACK_WIDGET_CREATION=true"
|
||||
export "TREE_SHAKE_ICONS=false"
|
||||
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
// clang-format off
|
||||
|
||||
#ifndef GeneratedPluginRegistrant_h
|
||||
#define GeneratedPluginRegistrant_h
|
||||
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface GeneratedPluginRegistrant : NSObject
|
||||
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
#endif /* GeneratedPluginRegistrant_h */
|
||||
@@ -1,14 +0,0 @@
|
||||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
// clang-format off
|
||||
|
||||
#import "GeneratedPluginRegistrant.h"
|
||||
|
||||
@implementation GeneratedPluginRegistrant
|
||||
|
||||
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -3,6 +3,8 @@ library country_code_picker;
|
||||
import 'package:collection/collection.dart' show IterableExtension;
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'src/bottom_sheet.dart';
|
||||
import 'src/constants.dart';
|
||||
import 'src/country_code.dart';
|
||||
import 'src/country_codes.dart';
|
||||
import 'src/selection_dialog.dart';
|
||||
@@ -11,6 +13,8 @@ export 'src/country_code.dart';
|
||||
export 'src/country_codes.dart';
|
||||
export 'src/country_localizations.dart';
|
||||
export 'src/selection_dialog.dart';
|
||||
export 'src/bottom_sheet.dart';
|
||||
export 'src/constants.dart';
|
||||
|
||||
class CountryCodePicker extends StatefulWidget {
|
||||
final ValueChanged<CountryCode>? onChanged;
|
||||
@@ -19,9 +23,11 @@ class CountryCodePicker extends StatefulWidget {
|
||||
final List<String> favorite;
|
||||
final TextStyle? textStyle;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final EdgeInsetsGeometry? margin;
|
||||
final bool showCountryOnly;
|
||||
final InputDecoration searchDecoration;
|
||||
final TextStyle? searchStyle;
|
||||
final bool? isFocused;
|
||||
final TextStyle? dialogTextStyle;
|
||||
final WidgetBuilder? emptySearchBuilder;
|
||||
final Function(CountryCode?)? builder;
|
||||
@@ -29,6 +35,9 @@ class CountryCodePicker extends StatefulWidget {
|
||||
final TextOverflow textOverflow;
|
||||
final Icon closeIcon;
|
||||
|
||||
///Picker style [BottomSheet] or [Dialog]
|
||||
final PickerStyle pickerStyle;
|
||||
|
||||
/// Barrier color of ModalBottomSheet
|
||||
final Color? barrierColor;
|
||||
|
||||
@@ -75,6 +84,9 @@ class CountryCodePicker extends StatefulWidget {
|
||||
/// Set to true if you want to hide the search part
|
||||
final bool hideSearch;
|
||||
|
||||
/// Set to true if you want to hide the close icon dialog
|
||||
final bool hideCloseIcon;
|
||||
|
||||
/// Set to true if you want to show drop down button
|
||||
final bool showDropDownButton;
|
||||
|
||||
@@ -85,6 +97,25 @@ class CountryCodePicker extends StatefulWidget {
|
||||
/// with customized codes.
|
||||
final List<Map<String, String>> countryList;
|
||||
|
||||
final EdgeInsetsGeometry dialogItemPadding;
|
||||
|
||||
final EdgeInsetsGeometry searchPadding;
|
||||
|
||||
///Use This To Hide The Header Text
|
||||
final bool hideHeaderText;
|
||||
|
||||
///Change The Header Text
|
||||
final String? headerText;
|
||||
|
||||
///Header Text Style
|
||||
final TextStyle headerTextStyle;
|
||||
|
||||
///Header Text Padding
|
||||
final EdgeInsets topBarPadding;
|
||||
|
||||
///Header Text Alignment
|
||||
final MainAxisAlignment headerAlignment;
|
||||
|
||||
const CountryCodePicker({
|
||||
this.onChanged,
|
||||
this.onInit,
|
||||
@@ -92,8 +123,10 @@ class CountryCodePicker extends StatefulWidget {
|
||||
this.favorite = const [],
|
||||
this.textStyle,
|
||||
this.padding = const EdgeInsets.all(8.0),
|
||||
this.margin,
|
||||
this.showCountryOnly = false,
|
||||
this.searchDecoration = const InputDecoration(),
|
||||
this.isFocused = false,
|
||||
this.searchStyle,
|
||||
this.dialogTextStyle,
|
||||
this.emptySearchBuilder,
|
||||
@@ -114,11 +147,20 @@ class CountryCodePicker extends StatefulWidget {
|
||||
this.comparator,
|
||||
this.countryFilter,
|
||||
this.hideSearch = false,
|
||||
this.hideCloseIcon = false,
|
||||
this.showDropDownButton = false,
|
||||
this.dialogSize,
|
||||
this.dialogBackgroundColor,
|
||||
this.closeIcon = const Icon(Icons.close),
|
||||
this.countryList = codes,
|
||||
this.pickerStyle = PickerStyle.dialog,
|
||||
this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
|
||||
this.headerAlignment = MainAxisAlignment.spaceBetween,
|
||||
this.headerText = "Select Country",
|
||||
this.headerTextStyle = const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
this.hideHeaderText = false,
|
||||
this.topBarPadding = const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20),
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@@ -127,16 +169,14 @@ class CountryCodePicker extends StatefulWidget {
|
||||
State<StatefulWidget> createState() {
|
||||
List<Map<String, String>> jsonList = countryList;
|
||||
|
||||
List<CountryCode> elements =
|
||||
jsonList.map((json) => CountryCode.fromJson(json)).toList();
|
||||
List<CountryCode> elements = jsonList.map((json) => CountryCode.fromJson(json)).toList();
|
||||
|
||||
if (comparator != null) {
|
||||
elements.sort(comparator);
|
||||
}
|
||||
|
||||
if (countryFilter != null && countryFilter!.isNotEmpty) {
|
||||
final uppercaseCustomList =
|
||||
countryFilter!.map((criteria) => criteria.toUpperCase()).toList();
|
||||
final uppercaseCustomList = countryFilter!.map((criteria) => criteria.toUpperCase()).toList();
|
||||
elements = elements
|
||||
.where((criteria) =>
|
||||
uppercaseCustomList.contains(criteria.code) ||
|
||||
@@ -145,7 +185,7 @@ class CountryCodePicker extends StatefulWidget {
|
||||
.toList();
|
||||
}
|
||||
|
||||
return CountryCodePickerState(elements);
|
||||
return CountryCodePickerState(elements, pickerStyle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,40 +193,42 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
CountryCode? selectedItem;
|
||||
List<CountryCode> elements = [];
|
||||
List<CountryCode> favoriteElements = [];
|
||||
PickerStyle pickerStyle;
|
||||
|
||||
CountryCodePickerState(this.elements);
|
||||
CountryCodePickerState(this.elements, this.pickerStyle);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget internalWidget;
|
||||
if (widget.builder != null) {
|
||||
internalWidget = InkWell(
|
||||
onTap: showCountryCodePickerDialog,
|
||||
onTap: pickerStyle == PickerStyle.dialog ? showCountryCodePickerDialog : showCountryCodePickerBottomSheet,
|
||||
child: widget.builder!(selectedItem),
|
||||
);
|
||||
} else {
|
||||
internalWidget = TextButton(
|
||||
onPressed: widget.enabled ? showCountryCodePickerDialog : null,
|
||||
onPressed: widget.enabled
|
||||
? pickerStyle == PickerStyle.dialog
|
||||
? showCountryCodePickerDialog
|
||||
: showCountryCodePickerBottomSheet
|
||||
: null,
|
||||
child: Padding(
|
||||
padding: widget.padding,
|
||||
child: Flex(
|
||||
direction: Axis.horizontal,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
if (widget.showFlagMain != null
|
||||
? widget.showFlagMain!
|
||||
: widget.showFlag)
|
||||
if (widget.showFlagMain != null ? widget.showFlagMain! : widget.showFlag)
|
||||
Flexible(
|
||||
flex: widget.alignLeft ? 0 : 1,
|
||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||
child: Container(
|
||||
clipBehavior: widget.flagDecoration == null
|
||||
? Clip.none
|
||||
: Clip.hardEdge,
|
||||
clipBehavior: widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
|
||||
decoration: widget.flagDecoration,
|
||||
margin: widget.alignLeft
|
||||
? const EdgeInsets.only(right: 16.0, left: 8.0)
|
||||
: const EdgeInsets.only(right: 16.0),
|
||||
margin: widget.margin ??
|
||||
(widget.alignLeft
|
||||
? const EdgeInsets.only(right: 16.0, left: 8.0)
|
||||
: const EdgeInsets.only(right: 16.0)),
|
||||
child: Image.asset(
|
||||
selectedItem!.flagUri!,
|
||||
package: 'country_code_picker',
|
||||
@@ -198,11 +240,8 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
Flexible(
|
||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||
child: Text(
|
||||
widget.showOnlyCountryWhenClosed
|
||||
? selectedItem!.toCountryStringOnly()
|
||||
: selectedItem.toString(),
|
||||
style: widget.textStyle ??
|
||||
Theme.of(context).textTheme.labelLarge,
|
||||
widget.showOnlyCountryWhenClosed ? selectedItem!.toCountryStringOnly() : selectedItem.toString(),
|
||||
style: widget.textStyle ?? Theme.of(context).textTheme.labelLarge,
|
||||
overflow: widget.textOverflow,
|
||||
),
|
||||
),
|
||||
@@ -211,9 +250,9 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
flex: widget.alignLeft ? 0 : 1,
|
||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||
child: Padding(
|
||||
padding: widget.alignLeft
|
||||
padding: (widget.alignLeft
|
||||
? const EdgeInsets.only(right: 16.0, left: 8.0)
|
||||
: const EdgeInsets.only(right: 16.0),
|
||||
: const EdgeInsets.only(right: 16.0)),
|
||||
child: Icon(
|
||||
Icons.arrow_drop_down,
|
||||
color: Colors.grey,
|
||||
@@ -244,11 +283,9 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
if (widget.initialSelection != null) {
|
||||
selectedItem = elements.firstWhere(
|
||||
(criteria) =>
|
||||
(criteria.code!.toUpperCase() ==
|
||||
widget.initialSelection!.toUpperCase()) ||
|
||||
(criteria.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
|
||||
(criteria.dialCode == widget.initialSelection) ||
|
||||
(criteria.name!.toUpperCase() ==
|
||||
widget.initialSelection!.toUpperCase()),
|
||||
(criteria.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
|
||||
orElse: () => elements[0]);
|
||||
} else {
|
||||
selectedItem = elements[0];
|
||||
@@ -264,11 +301,9 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
if (widget.initialSelection != null) {
|
||||
selectedItem = elements.firstWhere(
|
||||
(item) =>
|
||||
(item.code!.toUpperCase() ==
|
||||
widget.initialSelection!.toUpperCase()) ||
|
||||
(item.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
|
||||
(item.dialCode == widget.initialSelection) ||
|
||||
(item.name!.toUpperCase() ==
|
||||
widget.initialSelection!.toUpperCase()),
|
||||
(item.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
|
||||
orElse: () => elements[0]);
|
||||
} else {
|
||||
selectedItem = elements[0];
|
||||
@@ -286,7 +321,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
|
||||
void showCountryCodePickerDialog() async {
|
||||
final item = await showDialog(
|
||||
barrierColor: widget.barrierColor ?? Colors.grey.withOpacity(0.5),
|
||||
barrierColor: widget.barrierColor ?? Colors.grey.withAlpha(128),
|
||||
context: context,
|
||||
builder: (context) => Center(
|
||||
child: Dialog(
|
||||
@@ -297,16 +332,25 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
emptySearchBuilder: widget.emptySearchBuilder,
|
||||
searchDecoration: widget.searchDecoration,
|
||||
searchStyle: widget.searchStyle,
|
||||
isFocused: widget.isFocused,
|
||||
textStyle: widget.dialogTextStyle,
|
||||
boxDecoration: widget.boxDecoration,
|
||||
showFlag: widget.showFlagDialog ?? widget.showFlag,
|
||||
flagWidth: widget.flagWidth,
|
||||
size: widget.dialogSize,
|
||||
headerAlignment: widget.headerAlignment,
|
||||
headerText: widget.headerText,
|
||||
headerTextStyle: widget.headerTextStyle,
|
||||
hideHeaderText: widget.hideHeaderText,
|
||||
topBarPadding: widget.topBarPadding,
|
||||
backgroundColor: widget.dialogBackgroundColor,
|
||||
barrierColor: widget.barrierColor,
|
||||
hideSearch: widget.hideSearch,
|
||||
hideCloseIcon: widget.hideCloseIcon,
|
||||
closeIcon: widget.closeIcon,
|
||||
flagDecoration: widget.flagDecoration,
|
||||
dialogItemPadding: widget.dialogItemPadding,
|
||||
searchPadding: widget.searchPadding,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -321,6 +365,43 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
}
|
||||
}
|
||||
|
||||
void showCountryCodePickerBottomSheet() async {
|
||||
final item = await showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
builder: (ctx) {
|
||||
return SelectionBottomSheet(
|
||||
elements,
|
||||
favoriteElements,
|
||||
showCountryOnly: widget.showCountryOnly,
|
||||
emptySearchBuilder: widget.emptySearchBuilder,
|
||||
searchDecoration: widget.searchDecoration,
|
||||
searchStyle: widget.searchStyle,
|
||||
textStyle: widget.dialogTextStyle,
|
||||
boxDecoration: widget.boxDecoration,
|
||||
showFlag: widget.showFlagDialog ?? widget.showFlag,
|
||||
flagWidth: widget.flagWidth,
|
||||
size: widget.dialogSize,
|
||||
backgroundColor: widget.dialogBackgroundColor,
|
||||
barrierColor: widget.barrierColor,
|
||||
hideSearch: widget.hideSearch,
|
||||
closeIcon: widget.closeIcon,
|
||||
flagDecoration: widget.flagDecoration,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (item == null) return;
|
||||
|
||||
setState(() {
|
||||
selectedItem = item;
|
||||
});
|
||||
|
||||
_publishSelection(item);
|
||||
}
|
||||
|
||||
void _publishSelection(CountryCode countryCode) {
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged!(countryCode);
|
||||
|
||||
208
lib/src/bottom_sheet.dart
Normal file
208
lib/src/bottom_sheet.dart
Normal file
@@ -0,0 +1,208 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'country_code.dart';
|
||||
import 'country_localizations.dart';
|
||||
|
||||
/// selection bottom sheet used for selection of the country code
|
||||
class SelectionBottomSheet extends StatefulWidget {
|
||||
final List<CountryCode> elements;
|
||||
final bool? showCountryOnly;
|
||||
final InputDecoration searchDecoration;
|
||||
final TextStyle? searchStyle;
|
||||
final TextStyle? textStyle;
|
||||
final BoxDecoration? boxDecoration;
|
||||
final WidgetBuilder? emptySearchBuilder;
|
||||
final bool? showFlag;
|
||||
final double flagWidth;
|
||||
final Decoration? flagDecoration;
|
||||
final Size? size;
|
||||
final bool hideSearch;
|
||||
final Icon? closeIcon;
|
||||
|
||||
/// Background color of SelectionBottomSheet
|
||||
final Color? backgroundColor;
|
||||
|
||||
/// Boxshaow color of SelectionBottomSheet that matches CountryCodePicker barrier color
|
||||
final Color? barrierColor;
|
||||
|
||||
/// elements passed as favorite
|
||||
final List<CountryCode> favoriteElements;
|
||||
|
||||
SelectionBottomSheet(
|
||||
this.elements,
|
||||
this.favoriteElements, {
|
||||
Key? key,
|
||||
this.showCountryOnly,
|
||||
this.emptySearchBuilder,
|
||||
InputDecoration searchDecoration = const InputDecoration(),
|
||||
this.searchStyle,
|
||||
this.textStyle,
|
||||
this.boxDecoration,
|
||||
this.showFlag,
|
||||
this.flagDecoration,
|
||||
this.flagWidth = 32,
|
||||
this.size,
|
||||
this.backgroundColor,
|
||||
this.barrierColor,
|
||||
this.hideSearch = false,
|
||||
this.closeIcon,
|
||||
}) : searchDecoration = searchDecoration.prefixIcon == null
|
||||
? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
|
||||
: searchDecoration,
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _SelectionBottomSheetState();
|
||||
}
|
||||
|
||||
class _SelectionBottomSheetState extends State<SelectionBottomSheet> {
|
||||
/// this is useful for filtering purpose
|
||||
late List<CountryCode> filteredElements;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Padding(
|
||||
padding: const EdgeInsets.all(0.0),
|
||||
child: Container(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
width: widget.size?.width ?? MediaQuery.of(context).size.width,
|
||||
height:
|
||||
widget.size?.height ?? MediaQuery.of(context).size.height * 0.85,
|
||||
decoration: widget.boxDecoration ??
|
||||
BoxDecoration(
|
||||
color: widget.backgroundColor ?? Colors.white,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: widget.barrierColor ?? Colors.grey
|
||||
..withAlpha(255),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 3), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
IconButton(
|
||||
padding: const EdgeInsets.all(0),
|
||||
iconSize: 20,
|
||||
icon: widget.closeIcon!,
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
if (!widget.hideSearch)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: TextField(
|
||||
style: widget.searchStyle,
|
||||
decoration: widget.searchDecoration,
|
||||
onChanged: _filterElements,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
widget.favoriteElements.isEmpty
|
||||
? const DecoratedBox(decoration: BoxDecoration())
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...widget.favoriteElements.map(
|
||||
(f) => SimpleDialogOption(
|
||||
child: _buildOption(f),
|
||||
onPressed: () {
|
||||
_selectItem(f);
|
||||
},
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
],
|
||||
),
|
||||
if (filteredElements.isEmpty)
|
||||
_buildEmptySearchWidget(context)
|
||||
else
|
||||
...filteredElements.map(
|
||||
(e) => SimpleDialogOption(
|
||||
child: _buildOption(e),
|
||||
onPressed: () {
|
||||
_selectItem(e);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildOption(CountryCode e) {
|
||||
return SizedBox(
|
||||
width: 400,
|
||||
child: Flex(
|
||||
direction: Axis.horizontal,
|
||||
children: <Widget>[
|
||||
if (widget.showFlag!)
|
||||
Flexible(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(right: 16.0),
|
||||
decoration: widget.flagDecoration,
|
||||
clipBehavior:
|
||||
widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
|
||||
child: Image.asset(
|
||||
e.flagUri!,
|
||||
package: 'country_code_picker',
|
||||
width: widget.flagWidth,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: Text(
|
||||
widget.showCountryOnly!
|
||||
? e.toCountryStringOnly()
|
||||
: e.toLongString(),
|
||||
overflow: TextOverflow.fade,
|
||||
style: widget.textStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptySearchWidget(BuildContext context) {
|
||||
if (widget.emptySearchBuilder != null) {
|
||||
return widget.emptySearchBuilder!(context);
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: Text(CountryLocalizations.of(context)?.translate('no_country') ??
|
||||
'No country found'),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
filteredElements = widget.elements;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void _filterElements(String s) {
|
||||
s = s.toUpperCase();
|
||||
setState(() {
|
||||
filteredElements = widget.elements
|
||||
.where((e) =>
|
||||
e.code!.contains(s) ||
|
||||
e.dialCode!.contains(s) ||
|
||||
e.name!.toUpperCase().contains(s))
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
void _selectItem(CountryCode e) {
|
||||
Navigator.pop(context, e);
|
||||
}
|
||||
}
|
||||
1
lib/src/constants.dart
Normal file
1
lib/src/constants.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum PickerStyle { dialog, bottomSheet, fullScreen }
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:collection/collection.dart' show IterableExtension;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
|
||||
import 'country_codes.dart';
|
||||
import 'country_localizations.dart';
|
||||
@@ -39,6 +40,17 @@ class CountryCode {
|
||||
return CountryCode.fromJson(jsonCode!);
|
||||
}
|
||||
|
||||
static CountryCode? tryFromCountryCode(String countryCode) {
|
||||
try {
|
||||
return CountryCode.fromCountryCode(countryCode);
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to recognize country from countryCode: $countryCode');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
factory CountryCode.fromDialCode(String dialCode) {
|
||||
final Map<String, String>? jsonCode = codes.firstWhereOrNull(
|
||||
(code) => code['dial_code'] == dialCode,
|
||||
@@ -46,9 +58,20 @@ class CountryCode {
|
||||
return CountryCode.fromJson(jsonCode!);
|
||||
}
|
||||
|
||||
static CountryCode? tryFromDialCode(String dialCode) {
|
||||
try {
|
||||
return CountryCode.fromDialCode(dialCode);
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to recognize country from dialCode: $dialCode');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
CountryCode localize(BuildContext context) {
|
||||
return this
|
||||
..name = CountryLocalizations.of(context)?.translate(code) ?? name;
|
||||
final nam = CountryLocalizations.of(context)?.translate(code) ?? name;
|
||||
return this..name = nam ?? name;
|
||||
}
|
||||
|
||||
factory CountryCode.fromJson(Map<String, dynamic> json) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,14 +15,17 @@ class CountryLocalizations {
|
||||
);
|
||||
}
|
||||
|
||||
static const LocalizationsDelegate<CountryLocalizations> delegate =
|
||||
_CountryLocalizationsDelegate();
|
||||
static const LocalizationsDelegate<CountryLocalizations> delegate = _CountryLocalizationsDelegate();
|
||||
|
||||
static LocalizationsDelegate<CountryLocalizations> getDelegate({bool enableLocalization = true}) {
|
||||
return _CountryLocalizationsDelegate(enableLocalization: enableLocalization);
|
||||
}
|
||||
|
||||
late Map<String, String> _localizedStrings;
|
||||
|
||||
Future<bool> load() async {
|
||||
String jsonString = await rootBundle.loadString(
|
||||
'packages/country_code_picker/src/i18n/${locale.languageCode}.json');
|
||||
String jsonString =
|
||||
await rootBundle.loadString('packages/country_code_picker/src/i18n/${locale.languageCode}.json');
|
||||
Map<String, dynamic> jsonMap = json.decode(jsonString);
|
||||
|
||||
_localizedStrings = jsonMap.map((key, value) {
|
||||
@@ -37,9 +40,10 @@ class CountryLocalizations {
|
||||
}
|
||||
}
|
||||
|
||||
class _CountryLocalizationsDelegate
|
||||
extends LocalizationsDelegate<CountryLocalizations> {
|
||||
const _CountryLocalizationsDelegate();
|
||||
class _CountryLocalizationsDelegate extends LocalizationsDelegate<CountryLocalizations> {
|
||||
final bool enableLocalization;
|
||||
|
||||
const _CountryLocalizationsDelegate({this.enableLocalization = true});
|
||||
|
||||
@override
|
||||
bool isSupported(Locale locale) {
|
||||
@@ -119,7 +123,10 @@ class _CountryLocalizationsDelegate
|
||||
|
||||
@override
|
||||
Future<CountryLocalizations> load(Locale locale) async {
|
||||
CountryLocalizations localizations = CountryLocalizations(locale);
|
||||
// Use the provided locale if localization is enabled; otherwise, use English.
|
||||
Locale effectiveLocale = enableLocalization ? locale : const Locale('en');
|
||||
|
||||
CountryLocalizations localizations = CountryLocalizations(effectiveLocale);
|
||||
await localizations.load();
|
||||
return localizations;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
"CF": "Central African Republic",
|
||||
"TD": "Chad",
|
||||
"CL": "Chile",
|
||||
"CN": "China",
|
||||
"CN": "China's Mainland",
|
||||
"CX": "Christmas Island",
|
||||
"CC": "Cocos (Keeling) Islands",
|
||||
"CO": "Colombia",
|
||||
@@ -94,7 +94,7 @@
|
||||
"HM": "Heard Island and McDonald Islands",
|
||||
"VA": "Holy See (Vatican City State)",
|
||||
"HN": "Honduras",
|
||||
"HK": "Hong Kong",
|
||||
"HK": "Hong Kong China",
|
||||
"HU": "Hungary",
|
||||
"IS": "Iceland",
|
||||
"IN": "India",
|
||||
@@ -123,7 +123,7 @@
|
||||
"LI": "Liechtenstein",
|
||||
"LT": "Lithuania",
|
||||
"LU": "Luxembourg",
|
||||
"MO": "Macao",
|
||||
"MO": "Macao China",
|
||||
"MG": "Madagascar",
|
||||
"MW": "Malawi",
|
||||
"MY": "Malaysia",
|
||||
@@ -210,10 +210,7 @@
|
||||
"SE": "Sweden",
|
||||
"CH": "Switzerland",
|
||||
"SY": "Syrian Arab Republic",
|
||||
"TW": [
|
||||
"Taiwan, Province of China",
|
||||
"Taiwan"
|
||||
],
|
||||
"TW": "Taiwan China",
|
||||
"TJ": "Tajikistan",
|
||||
"TZ": "Tanzania, United Republic of",
|
||||
"TH": "Thailand",
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"BH": "Bahrein",
|
||||
"BD": "Bangladesh",
|
||||
"BB": "Barbade",
|
||||
"BY": "Bielorussie",
|
||||
"BY": "Biélorussie",
|
||||
"BE": "Belgique",
|
||||
"BZ": "Belize",
|
||||
"BJ": "Bénin",
|
||||
@@ -38,7 +38,7 @@
|
||||
"CM": "Cameroun",
|
||||
"CA": "Canada",
|
||||
"CV": "Cap-Vert",
|
||||
"KY": "Caïmanes",
|
||||
"KY": "Îles Caïmans",
|
||||
"CF": "Centrafricaine, République",
|
||||
"TD": "Tchad",
|
||||
"CL": "Chili",
|
||||
@@ -83,7 +83,7 @@
|
||||
"GI": "Gibraltar",
|
||||
"GR": "Grèce",
|
||||
"GL": "Groenland",
|
||||
"GD": "Grenada",
|
||||
"GD": "Grenade",
|
||||
"GP": "Guadeloupe",
|
||||
"GU": "Guam",
|
||||
"GT": "Guatemala",
|
||||
@@ -110,9 +110,9 @@
|
||||
"KZ": "Kazakhstan",
|
||||
"KE": "Kenya",
|
||||
"KI": "Kiribati",
|
||||
"KP": "Corée du Nord, République populaire démocratique",
|
||||
"KR": "Corée du Sud, République",
|
||||
"KW": "Koweit",
|
||||
"KP": "Corée du Nord",
|
||||
"KR": "Corée du Sud",
|
||||
"KW": "Koweït",
|
||||
"KG": "Kirghistan",
|
||||
"LA": "Laos",
|
||||
"LV": "Lettonie",
|
||||
@@ -179,7 +179,7 @@
|
||||
"SH": "Sainte-Hélène",
|
||||
"KN": "Saint-Christophe-et-Niévès",
|
||||
"LC": "Sainte-Lucie",
|
||||
"PM": "Saint Pierre and Miquelon",
|
||||
"PM": "Saint-Pierre-et-Miquelon",
|
||||
"VC": "Saint-Vincent et les Grenadines",
|
||||
"WS": "Samoa",
|
||||
"SM": "Saint-Marin",
|
||||
@@ -200,15 +200,15 @@
|
||||
"SD": "Soudan",
|
||||
"SR": "Suriname",
|
||||
"SJ": "Svalbard et Île Jan Mayen",
|
||||
"SZ": "Ngwane, Royaume d'Eswatini",
|
||||
"SZ": "Eswatini",
|
||||
"SE": "Suède",
|
||||
"CH": "Suisse",
|
||||
"SY": "Syrie",
|
||||
"TW": "Taïwan",
|
||||
"TJ": "Tadjikistan",
|
||||
"TZ": "Tanzanie, République unie",
|
||||
"TZ": "Tanzanie",
|
||||
"TH": "Thaïlande",
|
||||
"TL": "Timor Leste",
|
||||
"TL": "Timor-Leste",
|
||||
"TG": "Togo",
|
||||
"TK": "Tokelau",
|
||||
"TO": "Tonga",
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
"CK": "库克群岛",
|
||||
"CL": "智利",
|
||||
"CM": "喀麦隆",
|
||||
"CN": "中国",
|
||||
"CN": "中国大陆",
|
||||
"CO": "哥伦比亚",
|
||||
"CR": "哥斯达黎加",
|
||||
"CU": "古巴",
|
||||
@@ -93,7 +93,7 @@
|
||||
"GU": "关岛",
|
||||
"GW": "几内亚比绍",
|
||||
"GY": "圭亚那",
|
||||
"HK": "香港",
|
||||
"HK": "中国香港",
|
||||
"HM": "赫德岛和麦克唐纳群岛",
|
||||
"HN": "洪都拉斯",
|
||||
"HR": "克罗地亚",
|
||||
@@ -146,7 +146,7 @@
|
||||
"ML": "马里",
|
||||
"MM": "缅甸",
|
||||
"MN": "蒙古",
|
||||
"MO": "澳门",
|
||||
"MO": "中国澳门",
|
||||
"MP": "北马里亚纳群岛",
|
||||
"MQ": "马提尼克",
|
||||
"MR": "毛里塔尼亚",
|
||||
@@ -226,7 +226,7 @@
|
||||
"TR": "土耳其",
|
||||
"TT": "特立尼达和多巴哥",
|
||||
"TV": "图瓦卢",
|
||||
"TW": "中国台湾省",
|
||||
"TW": "中国台湾",
|
||||
"TZ": "坦桑尼亚",
|
||||
"UA": "乌克兰",
|
||||
"UG": "乌干达",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:diacritic/diacritic.dart';
|
||||
|
||||
import 'country_code.dart';
|
||||
import 'country_localizations.dart';
|
||||
@@ -9,7 +10,9 @@ class SelectionDialog extends StatefulWidget {
|
||||
final bool? showCountryOnly;
|
||||
final InputDecoration searchDecoration;
|
||||
final TextStyle? searchStyle;
|
||||
final bool? isFocused;
|
||||
final TextStyle? textStyle;
|
||||
final TextStyle headerTextStyle;
|
||||
final BoxDecoration? boxDecoration;
|
||||
final WidgetBuilder? emptySearchBuilder;
|
||||
final bool? showFlag;
|
||||
@@ -17,7 +20,12 @@ class SelectionDialog extends StatefulWidget {
|
||||
final Decoration? flagDecoration;
|
||||
final Size? size;
|
||||
final bool hideSearch;
|
||||
final bool hideCloseIcon;
|
||||
final Icon? closeIcon;
|
||||
final bool hideHeaderText;
|
||||
final String? headerText;
|
||||
final EdgeInsets topBarPadding;
|
||||
final MainAxisAlignment headerAlignment;
|
||||
|
||||
/// Background color of SelectionDialog
|
||||
final Color? backgroundColor;
|
||||
@@ -28,15 +36,25 @@ class SelectionDialog extends StatefulWidget {
|
||||
/// elements passed as favorite
|
||||
final List<CountryCode> favoriteElements;
|
||||
|
||||
final EdgeInsetsGeometry dialogItemPadding;
|
||||
|
||||
final EdgeInsetsGeometry searchPadding;
|
||||
|
||||
SelectionDialog(
|
||||
this.elements,
|
||||
this.favoriteElements, {
|
||||
Key? key,
|
||||
this.showCountryOnly,
|
||||
required this.hideHeaderText,
|
||||
this.emptySearchBuilder,
|
||||
required this.headerAlignment,
|
||||
required this.headerTextStyle,
|
||||
InputDecoration searchDecoration = const InputDecoration(),
|
||||
this.searchStyle,
|
||||
this.isFocused,
|
||||
this.textStyle,
|
||||
required this.topBarPadding,
|
||||
this.headerText,
|
||||
this.boxDecoration,
|
||||
this.showFlag,
|
||||
this.flagDecoration,
|
||||
@@ -45,7 +63,11 @@ class SelectionDialog extends StatefulWidget {
|
||||
this.backgroundColor,
|
||||
this.barrierColor,
|
||||
this.hideSearch = false,
|
||||
this.hideCloseIcon = false,
|
||||
this.closeIcon,
|
||||
this.dialogItemPadding =
|
||||
const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
|
||||
}) : searchDecoration = searchDecoration.prefixIcon == null
|
||||
? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
|
||||
: searchDecoration,
|
||||
@@ -73,7 +95,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: widget.barrierColor ?? Colors.grey.withOpacity(1),
|
||||
color: widget.barrierColor ?? Colors.grey.withAlpha(255),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 3), // changes position of shadow
|
||||
@@ -84,16 +106,35 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
IconButton(
|
||||
padding: const EdgeInsets.all(0),
|
||||
iconSize: 20,
|
||||
icon: widget.closeIcon!,
|
||||
onPressed: () => Navigator.pop(context),
|
||||
Padding(
|
||||
padding: !widget.hideHeaderText
|
||||
? widget.topBarPadding
|
||||
: EdgeInsets.zero,
|
||||
child: Row(
|
||||
mainAxisAlignment: widget.headerAlignment,
|
||||
children: [
|
||||
!widget.hideHeaderText && widget.headerText != null
|
||||
? Text(
|
||||
widget.headerText!,
|
||||
overflow: TextOverflow.fade,
|
||||
style: widget.headerTextStyle,
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
if (!widget.hideCloseIcon)
|
||||
IconButton(
|
||||
padding: const EdgeInsets.all(0),
|
||||
iconSize: 20,
|
||||
icon: widget.closeIcon!,
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!widget.hideSearch)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
padding: widget.searchPadding,
|
||||
child: TextField(
|
||||
autofocus: widget.isFocused ?? false,
|
||||
style: widget.searchStyle,
|
||||
decoration: widget.searchDecoration,
|
||||
onChanged: _filterElements,
|
||||
@@ -107,28 +148,28 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...widget.favoriteElements.map(
|
||||
(f) => SimpleDialogOption(
|
||||
child: _buildOption(f),
|
||||
onPressed: () {
|
||||
...widget.favoriteElements.map((f) => InkWell(
|
||||
onTap: () {
|
||||
_selectItem(f);
|
||||
},
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: widget.dialogItemPadding,
|
||||
child: _buildOption(f),
|
||||
))),
|
||||
const Divider(),
|
||||
],
|
||||
),
|
||||
if (filteredElements.isEmpty)
|
||||
_buildEmptySearchWidget(context)
|
||||
else
|
||||
...filteredElements.map(
|
||||
(e) => SimpleDialogOption(
|
||||
child: _buildOption(e),
|
||||
onPressed: () {
|
||||
...filteredElements.map((e) => InkWell(
|
||||
onTap: () {
|
||||
_selectItem(e);
|
||||
},
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: widget.dialogItemPadding,
|
||||
child: _buildOption(e),
|
||||
))),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -146,7 +187,11 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
if (widget.showFlag!)
|
||||
Flexible(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(right: 16.0),
|
||||
margin: Directionality.of(context) ==
|
||||
TextDirection
|
||||
.ltr // Here Adding padding depending on the locale language direction
|
||||
? const EdgeInsets.only(right: 16.0)
|
||||
: const EdgeInsets.only(left: 16.0),
|
||||
decoration: widget.flagDecoration,
|
||||
clipBehavior:
|
||||
widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
|
||||
@@ -190,13 +235,14 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
}
|
||||
|
||||
void _filterElements(String s) {
|
||||
s = s.toUpperCase();
|
||||
final normalizedSearch = removeDiacritics(s.toUpperCase());
|
||||
setState(() {
|
||||
filteredElements = widget.elements
|
||||
.where((e) =>
|
||||
e.code!.contains(s) ||
|
||||
e.dialCode!.contains(s) ||
|
||||
e.name!.toUpperCase().contains(s))
|
||||
e.code!.contains(normalizedSearch) ||
|
||||
e.dialCode!.contains(normalizedSearch) ||
|
||||
removeDiacritics(e.name!.toUpperCase())
|
||||
.contains(normalizedSearch))
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
name: country_code_picker
|
||||
description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox
|
||||
version: 3.0.0
|
||||
version: 3.4.0
|
||||
homepage: https://github.com/chandrabezzo/CountryCodePicker
|
||||
repository: https://github.com/chandrabezzo/CountryCodePicker
|
||||
issue_tracker: https://github.com/imtoori/CountryCodePicker/issues
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
sdk: ">=2.17.0 <4.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
collection: ^1.15.0
|
||||
diacritic: ^0.1.5
|
||||
|
||||
flutter:
|
||||
assets:
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 148 KiB After Width: | Height: | Size: 167 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 42 KiB |
Reference in New Issue
Block a user