diff --git a/.all-contributorsrc b/.all-contributorsrc new file mode 100644 index 00000000..f732b991 --- /dev/null +++ b/.all-contributorsrc @@ -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" +} diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index de50dd9d..8bbdd468 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -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* + tags: + - '[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 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0299a5..70e39f3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ -## 2.0.2 +## 3.4.1 - October 08 2025 +- Fix French country translations +- Removed Netherlands Antilles from country codes list + +## 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 diff --git a/CountryCodePicker.iml b/CountryCodePicker.iml deleted file mode 100644 index e9e2e7e2..00000000 --- a/CountryCodePicker.iml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index f5b73030..14bdce48 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ +![GitHub code size](https://img.shields.io/github/languages/code-size/chandrabezzo/CountryCodePicker) + +[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-) + +![GitHub contributors](https://img.shields.io/github/contributors/chandrabezzo/CountryCodePicker) [![Pub](https://img.shields.io/pub/v/country_code_picker.svg)](https://pub.dartlang.org/packages/country_code_picker) +[![Linkedin](https://i.stack.imgur.com/gVE0j.png) LinkedIn](https://www.linkedin.com/in/salvatore-giordano/) +[![Linkedin](https://i.stack.imgur.com/gVE0j.png) LinkedIn](https://www.linkedin.com/in/chandra-abdul-fattah/) # country_code_picker @@ -50,8 +57,9 @@ void _onCountryChange(CountryCode countryCode) { ### i18n -Just add the `CountryLocalizations.delegate` in the list of your app delegates +Just add the `CountryLocalizations.delegate` in the list of your app delegates +### Default Usage (Localization Enabled) ```dart return new MaterialApp( supportedLocales: [ @@ -133,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 | |-----|-----|------| @@ -167,3 +185,38 @@ Here is a list of properties available to customize your widget: ## Contributions Contributions of any kind are more than welcome! Feel free to fork and improve country_code_picker in any way you want, make a pull request, or open an issue. + + +## Getting involved +First of all, thank you for even considering to get involved. You are a real super :star: and we :heart: you! + +### Reporting bugs and issues +Use the configured [Github issue report template](https://github.com/imtoori/CountryCodePicker/issues/new?assignees=&labels=&template=bug_report.md&title=) when reporting an issue. Make sure to state your observations and expectations +as objectively and informative as possible so that we can understand your need and be able to troubleshoot. + +### 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)): + + + + + + + + + + + + +
Chandra Abdul Fattah
Chandra Abdul Fattah

🚇 💻
Salvatore Giordano
Salvatore Giordano

🚇 💻
Nilashish Roy
Nilashish Roy

🚇 💻
+ + + + + + +This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! \ No newline at end of file diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 00000000..61b6c4de --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java deleted file mode 100644 index d007606a..00000000 --- a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.flutter.plugins; - -import io.flutter.plugin.common.PluginRegistry; - -/** - * Generated file. Do not edit. - */ -public final class GeneratedPluginRegistrant { - public static void registerWith(PluginRegistry registry) { - if (alreadyRegisteredWith(registry)) { - return; - } - } - - private static boolean alreadyRegisteredWith(PluginRegistry registry) { - final String key = GeneratedPluginRegistrant.class.getCanonicalName(); - if (registry.hasPlugin(key)) { - return true; - } - registry.registrarFor(key); - return false; - } -} diff --git a/country_code_picker.iml b/country_code_picker.iml deleted file mode 100644 index d20080de..00000000 --- a/country_code_picker.iml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/example/.metadata b/example/.metadata index 01d2dcb9..af460189 100644 --- a/example/.metadata +++ b/example/.metadata @@ -1,10 +1,45 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled and should not be manually edited. +# This file should be version controlled. version: - revision: 0b8abb4724aa590dd0f429683339b1e045a1594d + revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 channel: stable project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + base_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + - platform: android + create_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + base_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + - platform: ios + create_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + base_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + - platform: linux + create_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + base_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + - platform: macos + create_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + base_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + - platform: web + create_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + base_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + - platform: windows + create_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + base_revision: 12cb4eb7a009f52b347b62ade7cb4854b926af72 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 00000000..61b6c4de --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/android/.gitignore b/example/android/.gitignore index bc2100d8..6f568019 100644 --- a/example/android/.gitignore +++ b/example/android/.gitignore @@ -5,3 +5,9 @@ gradle-wrapper.jar /gradlew.bat /local.properties GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 0f6a5e54..2a2d082b 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,67 +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 28 + namespace = "com.example.example" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - } - - lintOptions { - disable 'InvalidPackage' + compileOptions { + 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" - minSdkVersion 16 - targetSdkVersion 28 - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + 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. + 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" - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + source = "../.." } diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index c208884f..45d523a2 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,6 +1,7 @@ - diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 8bc6007d..3f41384d 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,21 +1,25 @@ - - + + diff --git a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt index 1656503f..e793a000 100644 --- a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt +++ b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt @@ -1,12 +1,6 @@ package com.example.example -import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterActivity -import io.flutter.embedding.engine.FlutterEngine -import io.flutter.plugins.GeneratedPluginRegistrant class MainActivity: FlutterActivity() { - override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { - GeneratedPluginRegistrant.registerWith(flutterEngine); - } } diff --git a/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml index 449a9f93..06952be7 100644 --- a/example/android/app/src/main/res/values-night/styles.xml +++ b/example/android/app/src/main/res/values-night/styles.xml @@ -3,14 +3,14 @@ + + diff --git a/example/android/app/src/profile/AndroidManifest.xml b/example/android/app/src/profile/AndroidManifest.xml index c208884f..45d523a2 100644 --- a/example/android/app/src/profile/AndroidManifest.xml +++ b/example/android/app/src/profile/AndroidManifest.xml @@ -1,6 +1,7 @@ - diff --git a/example/android/build.gradle b/example/android/build.gradle index 3100ad2d..d2ffbffa 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,31 +1,18 @@ -buildscript { - ext.kotlin_version = '1.3.50' - repositories { - google() - jcenter() - } - - dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() - jcenter() + mavenCentral() } } -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 } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 38c8d454..94adc3a3 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,4 +1,3 @@ org.gradle.jvmargs=-Xmx1536M -android.enableR8=true android.useAndroidX=true android.enableJetifier=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 296b146b..3c472b99 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 23 08:50:38 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 5a2f14fb..536165d3 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,15 +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 flutterProjectRoot = rootProject.projectDir.parentFile.toPath() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } } -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory +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" diff --git a/example/ios/.gitignore b/example/ios/.gitignore index e96ef602..7a7f9873 100644 --- a/example/ios/.gitignore +++ b/example/ios/.gitignore @@ -1,3 +1,4 @@ +**/dgph *.mode1v3 *.mode2v3 *.moved-aside @@ -18,6 +19,7 @@ Flutter/App.framework Flutter/Flutter.framework Flutter/Flutter.podspec Flutter/Generated.xcconfig +Flutter/ephemeral/ Flutter/app.flx Flutter/app.zip Flutter/flutter_assets/ diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id deleted file mode 100644 index 0957c029..00000000 --- a/example/ios/Flutter/.last_build_id +++ /dev/null @@ -1 +0,0 @@ -a5090a3d96b78c882fdfd4b39716ca8e \ No newline at end of file diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 6b4c0f78..9625e105 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -3,7 +3,7 @@ CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) + en CFBundleExecutable App CFBundleIdentifier @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 11.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 252c7539..0ff20a05 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -90,7 +90,6 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 97C147021CF9000F007C117D /* Info.plist */, - 97C146F11CF9000F007C117D /* Supporting Files */, 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, @@ -99,13 +98,6 @@ path = Runner; sourceTree = ""; }; - 97C146F11CF9000F007C117D /* Supporting Files */ = { - isa = PBXGroup; - children = ( - ); - name = "Supporting Files"; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -135,8 +127,8 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; - ORGANIZATIONNAME = "The Chromium Authors"; + LastUpgradeCheck = 1300; + ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; @@ -145,7 +137,7 @@ }; }; buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 9.3"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( @@ -179,6 +171,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -193,6 +186,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -280,7 +274,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -296,16 +290,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = XT9RJDBAYU; ENABLE_BITCODE = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Flutter", - ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Flutter", + "@executable_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = com.example.example; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -362,7 +352,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -411,11 +401,12 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -428,16 +419,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = XT9RJDBAYU; ENABLE_BITCODE = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Flutter", - ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Flutter", + "@executable_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = com.example.example; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -455,16 +442,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = XT9RJDBAYU; ENABLE_BITCODE = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Flutter", - ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Flutter", + "@executable_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = com.example.example; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140cf..c87d15a3 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - - - - + + - - CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Example CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -41,5 +43,9 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + diff --git a/example/ios/Runner/Runner-Bridging-Header.h b/example/ios/Runner/Runner-Bridging-Header.h index 7335fdf9..308a2a56 100644 --- a/example/ios/Runner/Runner-Bridging-Header.h +++ b/example/ios/Runner/Runner-Bridging-Header.h @@ -1 +1 @@ -#import "GeneratedPluginRegistrant.h" \ No newline at end of file +#import "GeneratedPluginRegistrant.h" diff --git a/example/lib/main.dart b/example/lib/main.dart index d0c2b136..30fe4dbc 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,20 +1,21 @@ import 'package:country_code_picker/country_code_picker.dart'; -import 'package:country_code_picker/country_localizations.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 StatefulWidget { + const MyApp({super.key}); + @override - _MyAppState createState() => new _MyAppState(); + MyAppState createState() => MyAppState(); } -class _MyAppState extends State { +class MyAppState extends State { @override Widget build(BuildContext context) { - return new MaterialApp( - supportedLocales: [ + return MaterialApp( + supportedLocales: const [ Locale("af"), Locale("am"), Locale("ar"), @@ -86,13 +87,14 @@ class _MyAppState extends State { Locale("vi"), Locale("zh") ], - localizationsDelegates: [ + localizationsDelegates: const [ CountryLocalizations.delegate, + /// CountryLocalizations.getDelegate(enableLocalization: false), // For no localization only english just declare delegate this way. GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], - home: new Scaffold( - appBar: new AppBar( + home: Scaffold( + appBar: AppBar( title: const Text('CountryPicker Example'), ), body: Center( @@ -103,26 +105,26 @@ class _MyAppState extends State { onChanged: print, // Initial selection and favorite can be one of code ('IT') OR dial_code('+39') initialSelection: 'IT', - favorite: ['+39', 'FR'], - countryFilter: ['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) => - print("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', - favorite: ['+39', 'FR'], - countryFilter: ['IT', 'FR'], + favorite: const ['+39', 'FR'], + countryFilter: const ['IT', 'FR'], // flag can be styled with BoxDecoration's `borderRadius` and `shape` fields flagDecoration: BoxDecoration( borderRadius: BorderRadius.circular(7), ), + pickerStyle: PickerStyle.bottomSheet, ), - SizedBox( + const SizedBox( width: 400, height: 60, child: CountryCodePicker( @@ -141,11 +143,11 @@ class _MyAppState extends State { width: 400, height: 60, child: CountryCodePicker( - onChanged: (e) => print(e.toLongString()), + onChanged: (element) => debugPrint(element.toLongString()), initialSelection: 'TF', showCountryOnly: true, showOnlyCountryWhenClosed: true, - favorite: ['+39', 'FR'], + favorite: const ['+39', 'FR'], ), ), SizedBox( @@ -157,7 +159,7 @@ class _MyAppState extends State { initialSelection: 'TF', showCountryOnly: true, showOnlyCountryWhenClosed: true, - favorite: ['+39', 'FR'], + favorite: const ['+39', 'FR'], ), ), ], diff --git a/example/linux/.gitignore b/example/linux/.gitignore new file mode 100644 index 00000000..d3896c98 --- /dev/null +++ b/example/linux/.gitignore @@ -0,0 +1 @@ +flutter/ephemeral diff --git a/example/linux/CMakeLists.txt b/example/linux/CMakeLists.txt new file mode 100644 index 00000000..74c66dd4 --- /dev/null +++ b/example/linux/CMakeLists.txt @@ -0,0 +1,138 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.10) +project(runner LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "example") +# The unique GTK application identifier for this application. See: +# https://wiki.gnome.org/HowDoI/ChooseApplicationID +set(APPLICATION_ID "com.example.example") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(SET CMP0063 NEW) + +# Load bundled libraries from the lib/ directory relative to the binary. +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Root filesystem for cross-building. +if(FLUTTER_TARGET_PLATFORM_SYSROOT) + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +# Define build configuration options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Define the application target. To change its name, change BINARY_NAME above, +# not the value here, or `flutter run` will no longer work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add dependency libraries. Add any application-specific dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) + +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) + install(FILES "${bundled_library}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endforeach(bundled_library) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/example/linux/flutter/CMakeLists.txt b/example/linux/flutter/CMakeLists.txt new file mode 100644 index 00000000..d5bd0164 --- /dev/null +++ b/example/linux/flutter/CMakeLists.txt @@ -0,0 +1,88 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/example/linux/flutter/generated_plugin_registrant.cc b/example/linux/flutter/generated_plugin_registrant.cc new file mode 100644 index 00000000..e71a16d2 --- /dev/null +++ b/example/linux/flutter/generated_plugin_registrant.cc @@ -0,0 +1,11 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + + +void fl_register_plugins(FlPluginRegistry* registry) { +} diff --git a/example/linux/flutter/generated_plugin_registrant.h b/example/linux/flutter/generated_plugin_registrant.h new file mode 100644 index 00000000..e0f0a47b --- /dev/null +++ b/example/linux/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void fl_register_plugins(FlPluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/example/linux/flutter/generated_plugins.cmake b/example/linux/flutter/generated_plugins.cmake new file mode 100644 index 00000000..2e1de87a --- /dev/null +++ b/example/linux/flutter/generated_plugins.cmake @@ -0,0 +1,23 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/example/linux/main.cc b/example/linux/main.cc new file mode 100644 index 00000000..e7c5c543 --- /dev/null +++ b/example/linux/main.cc @@ -0,0 +1,6 @@ +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/example/linux/my_application.cc b/example/linux/my_application.cc new file mode 100644 index 00000000..0ba8f430 --- /dev/null +++ b/example/linux/my_application.cc @@ -0,0 +1,104 @@ +#include "my_application.h" + +#include +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + char** dart_entrypoint_arguments; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + // Use a header bar when running in GNOME as this is the common style used + // by applications and is the setup most users will be using (e.g. Ubuntu + // desktop). + // If running on X and not using GNOME then just use a traditional title bar + // in case the window manager does more exotic layout, e.g. tiling. + // If running on Wayland assume the header bar will work (may need changing + // if future cases occur). + gboolean use_header_bar = TRUE; +#ifdef GDK_WINDOWING_X11 + GdkScreen* screen = gtk_window_get_screen(window); + if (GDK_IS_X11_SCREEN(screen)) { + const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + if (g_strcmp0(wm_name, "GNOME Shell") != 0) { + use_header_bar = FALSE; + } + } +#endif + if (use_header_bar) { + GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, "example"); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + } else { + gtk_window_set_title(window, "example"); + } + + gtk_window_set_default_size(window, 1280, 720); + gtk_widget_show(GTK_WIDGET(window)); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); + + FlView* view = fl_view_new(project); + gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); + + fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + + gtk_widget_grab_focus(GTK_WIDGET(view)); +} + +// Implements GApplication::local_command_line. +static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { + MyApplication* self = MY_APPLICATION(application); + // Strip out the first argument as it is the binary name. + self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); + + g_autoptr(GError) error = nullptr; + if (!g_application_register(application, nullptr, &error)) { + g_warning("Failed to register: %s", error->message); + *exit_status = 1; + return TRUE; + } + + g_application_activate(application); + *exit_status = 0; + + return TRUE; +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject* object) { + MyApplication* self = MY_APPLICATION(object); + g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_APPLICATION_CLASS(klass)->activate = my_application_activate; + G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, + "flags", G_APPLICATION_NON_UNIQUE, + nullptr)); +} diff --git a/example/linux/my_application.h b/example/linux/my_application.h new file mode 100644 index 00000000..72271d5e --- /dev/null +++ b/example/linux/my_application.h @@ -0,0 +1,18 @@ +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/example/macos/.gitignore b/example/macos/.gitignore index d2fd3772..746adbb6 100644 --- a/example/macos/.gitignore +++ b/example/macos/.gitignore @@ -3,4 +3,5 @@ **/Pods/ # Xcode-related +**/dgph **/xcuserdata/ diff --git a/example/macos/Runner.xcodeproj/project.pbxproj b/example/macos/Runner.xcodeproj/project.pbxproj index cc89c878..d9333e47 100644 --- a/example/macos/Runner.xcodeproj/project.pbxproj +++ b/example/macos/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXAggregateTarget section */ @@ -182,7 +182,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 33CC10EC2044A3C60003C045 = { @@ -235,6 +235,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3399D490228B24CF009A79C7 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -344,7 +345,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -423,7 +424,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -470,7 +471,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; diff --git a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index ae8ff59d..fb7259e1 100644 --- a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - - + + - - + + + + diff --git a/example/macos/Runner/Configs/AppInfo.xcconfig b/example/macos/Runner/Configs/AppInfo.xcconfig index cf9be60c..dda192bc 100644 --- a/example/macos/Runner/Configs/AppInfo.xcconfig +++ b/example/macos/Runner/Configs/AppInfo.xcconfig @@ -11,4 +11,4 @@ PRODUCT_NAME = example PRODUCT_BUNDLE_IDENTIFIER = com.example.example // The copyright displayed in application information -PRODUCT_COPYRIGHT = Copyright © 2021 com.example. All rights reserved. +PRODUCT_COPYRIGHT = Copyright © 2023 com.example. All rights reserved. diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d96115ce..0d08d87e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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: @@ -22,6 +22,7 @@ dependencies: sdk: flutter dev_dependencies: + flutter_lints: ^2.0.1 flutter_test: sdk: flutter diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 07c4146c..ef757abd 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -12,7 +12,7 @@ import 'package:hello_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); diff --git a/example/web/icons/Icon-maskable-192.png b/example/web/icons/Icon-maskable-192.png new file mode 100644 index 00000000..eb9b4d76 Binary files /dev/null and b/example/web/icons/Icon-maskable-192.png differ diff --git a/example/web/icons/Icon-maskable-512.png b/example/web/icons/Icon-maskable-512.png new file mode 100644 index 00000000..d69c5669 Binary files /dev/null and b/example/web/icons/Icon-maskable-512.png differ diff --git a/example/web/index.html b/example/web/index.html index 022b714c..be820e83 100644 --- a/example/web/index.html +++ b/example/web/index.html @@ -8,10 +8,13 @@ The path provided below has to start and end with a slash "/" in order for it to work correctly. - Fore more details: + For more details: * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base + + This is a placeholder for base href that will be replaced by the value of + the `--base-href` argument provided to `flutter build`. --> - + @@ -23,76 +26,34 @@ + + + example + + + + - diff --git a/example/web/manifest.json b/example/web/manifest.json index 8c012917..096edf8f 100644 --- a/example/web/manifest.json +++ b/example/web/manifest.json @@ -18,6 +18,18 @@ "src": "icons/Icon-512.png", "sizes": "512x512", "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" } ] } diff --git a/example/windows/.gitignore b/example/windows/.gitignore new file mode 100644 index 00000000..d492d0d9 --- /dev/null +++ b/example/windows/.gitignore @@ -0,0 +1,17 @@ +flutter/ephemeral/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ diff --git a/example/windows/CMakeLists.txt b/example/windows/CMakeLists.txt new file mode 100644 index 00000000..c0270746 --- /dev/null +++ b/example/windows/CMakeLists.txt @@ -0,0 +1,101 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.14) +project(example LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "example") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(SET CMP0063 NEW) + +# Define build configuration option. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() +# Define settings for the Profile build mode. +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build; see runner/CMakeLists.txt. +add_subdirectory("runner") + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/example/windows/flutter/CMakeLists.txt b/example/windows/flutter/CMakeLists.txt new file mode 100644 index 00000000..930d2071 --- /dev/null +++ b/example/windows/flutter/CMakeLists.txt @@ -0,0 +1,104 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.14) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + windows-x64 $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc new file mode 100644 index 00000000..8b6d4680 --- /dev/null +++ b/example/windows/flutter/generated_plugin_registrant.cc @@ -0,0 +1,11 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + + +void RegisterPlugins(flutter::PluginRegistry* registry) { +} diff --git a/example/windows/flutter/generated_plugin_registrant.h b/example/windows/flutter/generated_plugin_registrant.h new file mode 100644 index 00000000..dc139d85 --- /dev/null +++ b/example/windows/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void RegisterPlugins(flutter::PluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/example/windows/flutter/generated_plugins.cmake b/example/windows/flutter/generated_plugins.cmake new file mode 100644 index 00000000..b93c4c30 --- /dev/null +++ b/example/windows/flutter/generated_plugins.cmake @@ -0,0 +1,23 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/example/windows/runner/CMakeLists.txt b/example/windows/runner/CMakeLists.txt new file mode 100644 index 00000000..394917c0 --- /dev/null +++ b/example/windows/runner/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.14) +project(runner LANGUAGES CXX) + +# Define the application target. To change its name, change BINARY_NAME in the +# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer +# work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add preprocessor definitions for the build version. +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") + +# Disable Windows macros that collide with C++ standard library functions. +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") + +# Add dependency libraries and include directories. Add any application-specific +# dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/example/windows/runner/Runner.rc b/example/windows/runner/Runner.rc new file mode 100644 index 00000000..aecaa2b5 --- /dev/null +++ b/example/windows/runner/Runner.rc @@ -0,0 +1,121 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_APP_ICON ICON "resources\\app_icon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) +#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD +#else +#define VERSION_AS_NUMBER 1,0,0,0 +#endif + +#if defined(FLUTTER_VERSION) +#define VERSION_AS_STRING FLUTTER_VERSION +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "com.example" "\0" + VALUE "FileDescription", "example" "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "example" "\0" + VALUE "LegalCopyright", "Copyright (C) 2023 com.example. All rights reserved." "\0" + VALUE "OriginalFilename", "example.exe" "\0" + VALUE "ProductName", "example" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/example/windows/runner/flutter_window.cpp b/example/windows/runner/flutter_window.cpp new file mode 100644 index 00000000..b25e363e --- /dev/null +++ b/example/windows/runner/flutter_window.cpp @@ -0,0 +1,66 @@ +#include "flutter_window.h" + +#include + +#include "flutter/generated_plugin_registrant.h" + +FlutterWindow::FlutterWindow(const flutter::DartProject& project) + : project_(project) {} + +FlutterWindow::~FlutterWindow() {} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opportunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} diff --git a/example/windows/runner/flutter_window.h b/example/windows/runner/flutter_window.h new file mode 100644 index 00000000..6da0652f --- /dev/null +++ b/example/windows/runner/flutter_window.h @@ -0,0 +1,33 @@ +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include + +#include + +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow hosting a Flutter view running |project|. + explicit FlutterWindow(const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/example/windows/runner/main.cpp b/example/windows/runner/main.cpp new file mode 100644 index 00000000..a61bf80d --- /dev/null +++ b/example/windows/runner/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +#include "flutter_window.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t *command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = + GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.Create(L"example", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + ::MSG msg; + while (::GetMessage(&msg, nullptr, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/example/windows/runner/resource.h b/example/windows/runner/resource.h new file mode 100644 index 00000000..66a65d1e --- /dev/null +++ b/example/windows/runner/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/example/windows/runner/resources/app_icon.ico b/example/windows/runner/resources/app_icon.ico new file mode 100644 index 00000000..c04e20ca Binary files /dev/null and b/example/windows/runner/resources/app_icon.ico differ diff --git a/example/windows/runner/runner.exe.manifest b/example/windows/runner/runner.exe.manifest new file mode 100644 index 00000000..a42ea768 --- /dev/null +++ b/example/windows/runner/runner.exe.manifest @@ -0,0 +1,20 @@ + + + + + PerMonitorV2 + + + + + + + + + + + + + + + diff --git a/example/windows/runner/utils.cpp b/example/windows/runner/utils.cpp new file mode 100644 index 00000000..f5bf9fa0 --- /dev/null +++ b/example/windows/runner/utils.cpp @@ -0,0 +1,64 @@ +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE *unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, nullptr, 0, nullptr, nullptr); + std::string utf8_string; + if (target_length == 0 || target_length > utf8_string.max_size()) { + return utf8_string; + } + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, utf8_string.data(), + target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/example/windows/runner/utils.h b/example/windows/runner/utils.h new file mode 100644 index 00000000..3879d547 --- /dev/null +++ b/example/windows/runner/utils.h @@ -0,0 +1,19 @@ +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/example/windows/runner/win32_window.cpp b/example/windows/runner/win32_window.cpp new file mode 100644 index 00000000..041a3855 --- /dev/null +++ b/example/windows/runner/win32_window.cpp @@ -0,0 +1,288 @@ +#include "win32_window.h" + +#include +#include + +#include "resource.h" + +namespace { + +/// Window attribute that enables dark mode window decorations. +/// +/// Redefined in case the developer's machine has a Windows SDK older than +/// version 10.0.22000.0. +/// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +/// Registry key for app theme preference. +/// +/// A value of 0 indicates apps should use dark mode. A non-zero or missing +/// value indicates apps should use light mode. +constexpr const wchar_t kGetPreferredBrightnessRegKey[] = + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; +constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + } + FreeLibrary(user32_module); +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + UpdateTheme(window); + + return OnCreate(); +} + +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + + case WM_DWMCOLORIZATIONCOLORCHANGED: + UpdateTheme(hwnd); + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} + +void Win32Window::UpdateTheme(HWND const window) { + DWORD light_mode; + DWORD light_mode_size = sizeof(light_mode); + LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey, + kGetPreferredBrightnessRegValue, + RRF_RT_REG_DWORD, nullptr, &light_mode, + &light_mode_size); + + if (result == ERROR_SUCCESS) { + BOOL enable_dark_mode = light_mode == 0; + DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, + &enable_dark_mode, sizeof(enable_dark_mode)); + } +} diff --git a/example/windows/runner/win32_window.h b/example/windows/runner/win32_window.h new file mode 100644 index 00000000..c86632d8 --- /dev/null +++ b/example/windows/runner/win32_window.h @@ -0,0 +1,102 @@ +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates a win32 window with |title| that is positioned and sized using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responsponds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + // Update the window frame's theme to match the system theme. + static void UpdateTheme(HWND const window); + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/flags/sy.png b/flags/sy.png index 2ba6f6aa..c1bb556b 100644 Binary files a/flags/sy.png and b/flags/sy.png differ diff --git a/ios/Runner/GeneratedPluginRegistrant.h b/ios/Runner/GeneratedPluginRegistrant.h deleted file mode 100644 index 3b700eb4..00000000 --- a/ios/Runner/GeneratedPluginRegistrant.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// Generated file. Do not edit. -// - -#ifndef GeneratedPluginRegistrant_h -#define GeneratedPluginRegistrant_h - -#import - -@interface GeneratedPluginRegistrant : NSObject -+ (void)registerWithRegistry:(NSObject*)registry; -@end - -#endif /* GeneratedPluginRegistrant_h */ diff --git a/ios/Runner/GeneratedPluginRegistrant.m b/ios/Runner/GeneratedPluginRegistrant.m deleted file mode 100644 index 60dfa42b..00000000 --- a/ios/Runner/GeneratedPluginRegistrant.m +++ /dev/null @@ -1,12 +0,0 @@ -// -// Generated file. Do not edit. -// - -#import "GeneratedPluginRegistrant.h" - -@implementation GeneratedPluginRegistrant - -+ (void)registerWithRegistry:(NSObject*)registry { -} - -@end diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index c979e12b..7c33ff85 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -1,15 +1,20 @@ library country_code_picker; import 'package:collection/collection.dart' show IterableExtension; -import 'package:country_code_picker/country_code.dart'; -import 'package:country_code_picker/country_codes.dart'; -import 'package:country_code_picker/selection_dialog.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; -import 'package:universal_platform/universal_platform.dart'; -export 'country_code.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'; + +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? onChanged; @@ -18,9 +23,11 @@ class CountryCodePicker extends StatefulWidget { final List 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; @@ -28,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; @@ -74,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; @@ -84,15 +97,36 @@ class CountryCodePicker extends StatefulWidget { /// with customized codes. final List> countryList; - CountryCodePicker({ + 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, this.initialSelection, 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, @@ -113,37 +147,45 @@ 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); @override + // ignore: no_logic_in_create_state State createState() { List> jsonList = countryList; - List elements = - jsonList.map((json) => CountryCode.fromJson(json)).toList(); + List elements = jsonList.map((json) => CountryCode.fromJson(json)).toList(); if (comparator != null) { elements.sort(comparator); } if (countryFilter != null && countryFilter!.isNotEmpty) { - final uppercaseCustomList = - countryFilter!.map((c) => c.toUpperCase()).toList(); + final uppercaseCustomList = countryFilter!.map((criteria) => criteria.toUpperCase()).toList(); elements = elements - .where((c) => - uppercaseCustomList.contains(c.code) || - uppercaseCustomList.contains(c.name) || - uppercaseCustomList.contains(c.dialCode)) + .where((criteria) => + uppercaseCustomList.contains(criteria.code) || + uppercaseCustomList.contains(criteria.name) || + uppercaseCustomList.contains(criteria.dialCode)) .toList(); } - return CountryCodePickerState(elements); + return CountryCodePickerState(elements, pickerStyle); } } @@ -151,40 +193,42 @@ class CountryCodePickerState extends State { CountryCode? selectedItem; List elements = []; List favoriteElements = []; + PickerStyle pickerStyle; - CountryCodePickerState(this.elements); + CountryCodePickerState(this.elements, this.pickerStyle); @override Widget build(BuildContext context) { - Widget _widget; - if (widget.builder != null) - _widget = InkWell( - onTap: showCountryCodePickerDialog, + Widget internalWidget; + if (widget.builder != null) { + internalWidget = InkWell( + onTap: pickerStyle == PickerStyle.dialog ? showCountryCodePickerDialog : showCountryCodePickerBottomSheet, child: widget.builder!(selectedItem), ); - else { - _widget = TextButton( - onPressed: widget.enabled ? showCountryCodePickerDialog : null, + } else { + internalWidget = TextButton( + onPressed: widget.enabled + ? pickerStyle == PickerStyle.dialog + ? showCountryCodePickerDialog + : showCountryCodePickerBottomSheet + : null, child: Padding( padding: widget.padding, child: Flex( direction: Axis.horizontal, mainAxisSize: MainAxisSize.min, children: [ - 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', @@ -196,11 +240,8 @@ class CountryCodePickerState extends State { Flexible( fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, child: Text( - widget.showOnlyCountryWhenClosed - ? selectedItem!.toCountryStringOnly() - : selectedItem.toString(), - style: - widget.textStyle ?? Theme.of(context).textTheme.button, + widget.showOnlyCountryWhenClosed ? selectedItem!.toCountryStringOnly() : selectedItem.toString(), + style: widget.textStyle ?? Theme.of(context).textTheme.labelLarge, overflow: widget.textOverflow, ), ), @@ -209,9 +250,9 @@ class CountryCodePickerState extends State { 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, @@ -223,14 +264,14 @@ class CountryCodePickerState extends State { ), ); } - return _widget; + return internalWidget; } @override void didChangeDependencies() { super.didChangeDependencies(); - this.elements = elements.map((e) => e.localize(context)).toList(); + elements = elements.map((element) => element.localize(context)).toList(); _onInit(selectedItem); } @@ -241,12 +282,10 @@ class CountryCodePickerState extends State { if (oldWidget.initialSelection != widget.initialSelection) { if (widget.initialSelection != null) { selectedItem = elements.firstWhere( - (e) => - (e.code!.toUpperCase() == - widget.initialSelection!.toUpperCase()) || - (e.dialCode == widget.initialSelection) || - (e.name!.toUpperCase() == - widget.initialSelection!.toUpperCase()), + (criteria) => + (criteria.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) || + (criteria.dialCode == widget.initialSelection) || + (criteria.name!.toUpperCase() == widget.initialSelection!.toUpperCase()), orElse: () => elements[0]); } else { selectedItem = elements[0]; @@ -261,74 +300,31 @@ class CountryCodePickerState extends State { if (widget.initialSelection != null) { selectedItem = elements.firstWhere( - (e) => - (e.code!.toUpperCase() == - widget.initialSelection!.toUpperCase()) || - (e.dialCode == widget.initialSelection) || - (e.name!.toUpperCase() == widget.initialSelection!.toUpperCase()), + (item) => + (item.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) || + (item.dialCode == widget.initialSelection) || + (item.name!.toUpperCase() == widget.initialSelection!.toUpperCase()), orElse: () => elements[0]); } else { selectedItem = elements[0]; } favoriteElements = elements - .where((e) => - widget.favorite.firstWhereOrNull((f) => - e.code!.toUpperCase() == f.toUpperCase() || - e.dialCode == f || - e.name!.toUpperCase() == f.toUpperCase()) != + .where((item) => + widget.favorite.firstWhereOrNull((criteria) => + item.code!.toUpperCase() == criteria.toUpperCase() || + item.dialCode == criteria || + item.name!.toUpperCase() == criteria.toUpperCase()) != null) .toList(); } - void showCountryCodePickerDialog() { - if (!UniversalPlatform.isAndroid && !UniversalPlatform.isIOS) { - showDialog( - barrierColor: widget.barrierColor ?? Colors.grey.withOpacity(0.5), - // backgroundColor: widget.backgroundColor ?? Colors.transparent, - context: context, - builder: (context) => Center( - child: Container( - constraints: BoxConstraints(maxHeight: 500, maxWidth: 400), - child: Dialog( - child: SelectionDialog( - elements, - favoriteElements, - showCountryOnly: widget.showCountryOnly, - emptySearchBuilder: widget.emptySearchBuilder, - searchDecoration: widget.searchDecoration, - searchStyle: widget.searchStyle, - textStyle: widget.dialogTextStyle, - boxDecoration: widget.boxDecoration, - showFlag: widget.showFlagDialog != null - ? 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, - ), - ), - ), - ), - ).then((e) { - if (e != null) { - setState(() { - selectedItem = e; - }); - - _publishSelection(e); - } - }); - } else { - showMaterialModalBottomSheet( - barrierColor: widget.barrierColor ?? Colors.grey.withOpacity(0.5), - backgroundColor: widget.backgroundColor ?? Colors.transparent, - context: context, - builder: (context) => Center( + void showCountryCodePickerDialog() async { + final item = await showDialog( + barrierColor: widget.barrierColor ?? Colors.grey.withAlpha(128), + context: context, + builder: (context) => Center( + child: Dialog( child: SelectionDialog( elements, favoriteElements, @@ -336,41 +332,85 @@ class CountryCodePickerState extends State { emptySearchBuilder: widget.emptySearchBuilder, searchDecoration: widget.searchDecoration, searchStyle: widget.searchStyle, + isFocused: widget.isFocused, textStyle: widget.dialogTextStyle, boxDecoration: widget.boxDecoration, - showFlag: widget.showFlagDialog != null - ? widget.showFlagDialog - : widget.showFlag, + showFlag: widget.showFlagDialog ?? widget.showFlag, flagWidth: widget.flagWidth, - flagDecoration: widget.flagDecoration, 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, ), ), - ).then((e) { - if (e != null) { - setState(() { - selectedItem = e; - }); - - _publishSelection(e); - } + ), + ); + + if (item != null) { + setState(() { + selectedItem = item; }); + + _publishSelection(item); } } - void _publishSelection(CountryCode e) { + 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!(e); + widget.onChanged!(countryCode); } } - void _onInit(CountryCode? e) { + void _onInit(CountryCode? countryCode) { if (widget.onInit != null) { - widget.onInit!(e); + widget.onInit!(countryCode); } } } diff --git a/lib/country_codes.dart b/lib/country_codes.dart deleted file mode 100644 index 7e7c0823..00000000 --- a/lib/country_codes.dart +++ /dev/null @@ -1,1237 +0,0 @@ -const List> codes = [ - { - "name": "افغانستان", - "code": "AF", - "dial_code": "+93", - }, - { - "name": "Åland", - "code": "AX", - "dial_code": "+358", - }, - { - "name": "Shqipëria", - "code": "AL", - "dial_code": "+355", - }, - { - "name": "الجزائر", - "code": "DZ", - "dial_code": "+213", - }, - { - "name": "American Samoa", - "code": "AS", - "dial_code": "+1684", - }, - { - "name": "Andorra", - "code": "AD", - "dial_code": "+376", - }, - { - "name": "Angola", - "code": "AO", - "dial_code": "+244", - }, - { - "name": "Anguilla", - "code": "AI", - "dial_code": "+1264", - }, - { - "name": "Antarctica", - "code": "AQ", - "dial_code": "+672", - }, - { - "name": "Antigua and Barbuda", - "code": "AG", - "dial_code": "+1268", - }, - { - "name": "Argentina", - "code": "AR", - "dial_code": "+54", - }, - { - "name": "Հայաստան", - "code": "AM", - "dial_code": "+374", - }, - { - "name": "Aruba", - "code": "AW", - "dial_code": "+297", - }, - { - "name": "Australia", - "code": "AU", - "dial_code": "+61", - }, - { - "name": "Österreich", - "code": "AT", - "dial_code": "+43", - }, - { - "name": "Azərbaycan", - "code": "AZ", - "dial_code": "+994", - }, - { - "name": "Bahamas", - "code": "BS", - "dial_code": "+1242", - }, - { - "name": "‏البحرين", - "code": "BH", - "dial_code": "+973", - }, - { - "name": "Bangladesh", - "code": "BD", - "dial_code": "+880", - }, - { - "name": "Barbados", - "code": "BB", - "dial_code": "+1246", - }, - { - "name": "Белару́сь", - "code": "BY", - "dial_code": "+375", - }, - { - "name": "België", - "code": "BE", - "dial_code": "+32", - }, - { - "name": "Belize", - "code": "BZ", - "dial_code": "+501", - }, - { - "name": "Bénin", - "code": "BJ", - "dial_code": "+229", - }, - { - "name": "Bermuda", - "code": "BM", - "dial_code": "+1441", - }, - { - "name": "ʼbrug-yul", - "code": "BT", - "dial_code": "+975", - }, - { - "name": "Bolivia", - "code": "BO", - "dial_code": "+591", - }, - { - "name": "Bosna i Hercegovina", - "code": "BA", - "dial_code": "+387", - }, - { - "name": "Botswana", - "code": "BW", - "dial_code": "+267", - }, - { - "name": "Bouvetøya", - "code": "BV", - "dial_code": "+47", - }, - { - "name": "Brasil", - "code": "BR", - "dial_code": "+55", - }, - { - "name": "British Indian Ocean Territory", - "code": "IO", - "dial_code": "+246", - }, - { - "name": "Negara Brunei Darussalam", - "code": "BN", - "dial_code": "+673", - }, - { - "name": "България", - "code": "BG", - "dial_code": "+359", - }, - { - "name": "Burkina Faso", - "code": "BF", - "dial_code": "+226", - }, - { - "name": "Burundi", - "code": "BI", - "dial_code": "+257", - }, - { - "name": "Cambodia", - "code": "KH", - "dial_code": "+855", - }, - { - "name": "Cameroon", - "code": "CM", - "dial_code": "+237", - }, - { - "name": "Canada", - "code": "CA", - "dial_code": "+1", - }, - { - "name": "Cabo Verde", - "code": "CV", - "dial_code": "+238", - }, - { - "name": "Cayman Islands", - "code": "KY", - "dial_code": "+1345", - }, - { - "name": "Ködörösêse tî Bêafrîka", - "code": "CF", - "dial_code": "+236", - }, - { - "name": "Tchad", - "code": "TD", - "dial_code": "+235", - }, - { - "name": "Chile", - "code": "CL", - "dial_code": "+56", - }, - { - "name": "中国", - "code": "CN", - "dial_code": "+86", - }, - { - "name": "Christmas Island", - "code": "CX", - "dial_code": "+61", - }, - { - "name": "Cocos (Keeling) Islands", - "code": "CC", - "dial_code": "+61", - }, - { - "name": "Colombia", - "code": "CO", - "dial_code": "+57", - }, - { - "name": "Komori", - "code": "KM", - "dial_code": "+269", - }, - { - "name": "République du Congo", - "code": "CG", - "dial_code": "+242", - }, - { - "name": "République démocratique du Congo", - "code": "CD", - "dial_code": "+243", - }, - { - "name": "Cook Islands", - "code": "CK", - "dial_code": "+682", - }, - { - "name": "Costa Rica", - "code": "CR", - "dial_code": "+506", - }, - { - "name": "Côte d'Ivoire", - "code": "CI", - "dial_code": "+225", - }, - { - "name": "Hrvatska", - "code": "HR", - "dial_code": "+385", - }, - { - "name": "Cuba", - "code": "CU", - "dial_code": "+53", - }, - { - "name": "Κύπρος", - "code": "CY", - "dial_code": "+357", - }, - { - "name": "Česká republika", - "code": "CZ", - "dial_code": "+420", - }, - { - "name": "Danmark", - "code": "DK", - "dial_code": "+45", - }, - { - "name": "Djibouti", - "code": "DJ", - "dial_code": "+253", - }, - { - "name": "Dominica", - "code": "DM", - "dial_code": "+1767", - }, - { - "name": "República Dominicana", - "code": "DO", - "dial_code": "+1", - }, - { - "name": "Ecuador", - "code": "EC", - "dial_code": "+593", - }, - { - "name": "مصر‎", - "code": "EG", - "dial_code": "+20", - }, - { - "name": "El Salvador", - "code": "SV", - "dial_code": "+503", - }, - { - "name": "Guinea Ecuatorial", - "code": "GQ", - "dial_code": "+240", - }, - { - "name": "ኤርትራ", - "code": "ER", - "dial_code": "+291", - }, - { - "name": "Eesti", - "code": "EE", - "dial_code": "+372", - }, - { - "name": "ኢትዮጵያ", - "code": "ET", - "dial_code": "+251", - }, - { - "name": "Falkland Islands", - "code": "FK", - "dial_code": "+500", - }, - { - "name": "Føroyar", - "code": "FO", - "dial_code": "+298", - }, - { - "name": "Fiji", - "code": "FJ", - "dial_code": "+679", - }, - { - "name": "Suomi", - "code": "FI", - "dial_code": "+358", - }, - { - "name": "France", - "code": "FR", - "dial_code": "+33", - }, - { - "name": "Guyane française", - "code": "GF", - "dial_code": "+594", - }, - { - "name": "Polynésie française", - "code": "PF", - "dial_code": "+689", - }, - { - "name": "Territoire des Terres australes et antarctiques fr", - "code": "TF", - "dial_code": "+262", - }, - { - "name": "Gabon", - "code": "GA", - "dial_code": "+241", - }, - { - "name": "Gambia", - "code": "GM", - "dial_code": "+220", - }, - { - "name": "საქართველო", - "code": "GE", - "dial_code": "+995", - }, - { - "name": "Deutschland", - "code": "DE", - "dial_code": "+49", - }, - { - "name": "Ghana", - "code": "GH", - "dial_code": "+233", - }, - { - "name": "Gibraltar", - "code": "GI", - "dial_code": "+350", - }, - { - "name": "Ελλάδα", - "code": "GR", - "dial_code": "+30", - }, - { - "name": "Kalaallit Nunaat", - "code": "GL", - "dial_code": "+299", - }, - { - "name": "Grenada", - "code": "GD", - "dial_code": "+1473", - }, - { - "name": "Guadeloupe", - "code": "GP", - "dial_code": "+590", - }, - { - "name": "Guam", - "code": "GU", - "dial_code": "+1671", - }, - { - "name": "Guatemala", - "code": "GT", - "dial_code": "+502", - }, - { - "name": "Guernsey", - "code": "GG", - "dial_code": "+44", - }, - { - "name": "Guinée", - "code": "GN", - "dial_code": "+224", - }, - { - "name": "Guiné-Bissau", - "code": "GW", - "dial_code": "+245", - }, - { - "name": "Guyana", - "code": "GY", - "dial_code": "+592", - }, - { - "name": "Haïti", - "code": "HT", - "dial_code": "+509", - }, - { - "name": "Heard Island and McDonald Islands", - "code": "HM", - "dial_code": "+0", - }, - { - "name": "Vaticano", - "code": "VA", - "dial_code": "+379", - }, - { - "name": "Honduras", - "code": "HN", - "dial_code": "+504", - }, - { - "name": "香港", - "code": "HK", - "dial_code": "+852", - }, - { - "name": "Magyarország", - "code": "HU", - "dial_code": "+36", - }, - { - "name": "Ísland", - "code": "IS", - "dial_code": "+354", - }, - { - "name": "भारत", - "code": "IN", - "dial_code": "+91", - }, - { - "name": "Indonesia", - "code": "ID", - "dial_code": "+62", - }, - { - "name": "ایران", - "code": "IR", - "dial_code": "+98", - }, - { - "name": "العراق", - "code": "IQ", - "dial_code": "+964", - }, - { - "name": "Éire", - "code": "IE", - "dial_code": "+353", - }, - { - "name": "Isle of Man", - "code": "IM", - "dial_code": "+44", - }, - { - "name": "ישראל", - "code": "IL", - "dial_code": "+972", - }, - { - "name": "Italia", - "code": "IT", - "dial_code": "+39", - }, - { - "name": "Jamaica", - "code": "JM", - "dial_code": "+1876", - }, - { - "name": "日本", - "code": "JP", - "dial_code": "+81", - }, - { - "name": "Jersey", - "code": "JE", - "dial_code": "+44", - }, - { - "name": "الأردن", - "code": "JO", - "dial_code": "+962", - }, - { - "name": "Қазақстан", - "code": "KZ", - "dial_code": "+7", - }, - { - "name": "Kenya", - "code": "KE", - "dial_code": "+254", - }, - { - "name": "Kiribati", - "code": "KI", - "dial_code": "+686", - }, - { - "name": "북한", - "code": "KP", - "dial_code": "+850", - }, - { - "name": "대한민국", - "code": "KR", - "dial_code": "+82", - }, - { - "name": "Republika e Kosovës", - "code": "XK", - "dial_code": "+383", - }, - { - "name": "الكويت", - "code": "KW", - "dial_code": "+965", - }, - { - "name": "Кыргызстан", - "code": "KG", - "dial_code": "+996", - }, - { - "name": "ສປປລາວ", - "code": "LA", - "dial_code": "+856", - }, - { - "name": "Latvija", - "code": "LV", - "dial_code": "+371", - }, - { - "name": "لبنان", - "code": "LB", - "dial_code": "+961", - }, - { - "name": "Lesotho", - "code": "LS", - "dial_code": "+266", - }, - { - "name": "Liberia", - "code": "LR", - "dial_code": "+231", - }, - { - "name": "‏ليبيا", - "code": "LY", - "dial_code": "+218", - }, - { - "name": "Liechtenstein", - "code": "LI", - "dial_code": "+423", - }, - { - "name": "Lietuva", - "code": "LT", - "dial_code": "+370", - }, - { - "name": "Luxembourg", - "code": "LU", - "dial_code": "+352", - }, - { - "name": "澳門", - "code": "MO", - "dial_code": "+853", - }, - { - "name": "Македонија", - "code": "MK", - "dial_code": "+389", - }, - { - "name": "Madagasikara", - "code": "MG", - "dial_code": "+261", - }, - { - "name": "Malawi", - "code": "MW", - "dial_code": "+265", - }, - { - "name": "Malaysia", - "code": "MY", - "dial_code": "+60", - }, - { - "name": "Maldives", - "code": "MV", - "dial_code": "+960", - }, - { - "name": "Mali", - "code": "ML", - "dial_code": "+223", - }, - { - "name": "Malta", - "code": "MT", - "dial_code": "+356", - }, - { - "name": "M̧ajeļ", - "code": "MH", - "dial_code": "+692", - }, - { - "name": "Martinique", - "code": "MQ", - "dial_code": "+596", - }, - { - "name": "موريتانيا", - "code": "MR", - "dial_code": "+222", - }, - { - "name": "Maurice", - "code": "MU", - "dial_code": "+230", - }, - { - "name": "Mayotte", - "code": "YT", - "dial_code": "+262", - }, - { - "name": "México", - "code": "MX", - "dial_code": "+52", - }, - { - "name": "Micronesia", - "code": "FM", - "dial_code": "+691", - }, - { - "name": "Moldova", - "code": "MD", - "dial_code": "+373", - }, - { - "name": "Monaco", - "code": "MC", - "dial_code": "+377", - }, - { - "name": "Монгол улс", - "code": "MN", - "dial_code": "+976", - }, - { - "name": "Црна Гора", - "code": "ME", - "dial_code": "+382", - }, - { - "name": "Montserrat", - "code": "MS", - "dial_code": "+1664", - }, - { - "name": "المغرب", - "code": "MA", - "dial_code": "+212", - }, - { - "name": "Moçambique", - "code": "MZ", - "dial_code": "+258", - }, - { - "name": "Myanmar", - "code": "MM", - "dial_code": "+95", - }, - { - "name": "Namibia", - "code": "NA", - "dial_code": "+264", - }, - { - "name": "Nauru", - "code": "NR", - "dial_code": "+674", - }, - { - "name": "नेपाल", - "code": "NP", - "dial_code": "+977", - }, - { - "name": "Nederland", - "code": "NL", - "dial_code": "+31", - }, - { - "name": "Netherlands Antilles", - "code": "AN", - "dial_code": "+599", - }, - { - "name": "Nouvelle-Calédonie", - "code": "NC", - "dial_code": "+687", - }, - { - "name": "New Zealand", - "code": "NZ", - "dial_code": "+64", - }, - { - "name": "Nicaragua", - "code": "NI", - "dial_code": "+505", - }, - { - "name": "Niger", - "code": "NE", - "dial_code": "+227", - }, - { - "name": "Nigeria", - "code": "NG", - "dial_code": "+234", - }, - { - "name": "Niuē", - "code": "NU", - "dial_code": "+683", - }, - { - "name": "Norfolk Island", - "code": "NF", - "dial_code": "+672", - }, - { - "name": "Northern Mariana Islands", - "code": "MP", - "dial_code": "+1670", - }, - { - "name": "Norge", - "code": "NO", - "dial_code": "+47", - }, - { - "name": "عمان", - "code": "OM", - "dial_code": "+968", - }, - { - "name": "Pakistan", - "code": "PK", - "dial_code": "+92", - }, - { - "name": "Palau", - "code": "PW", - "dial_code": "+680", - }, - { - "name": "فلسطين", - "code": "PS", - "dial_code": "+970", - }, - { - "name": "Panamá", - "code": "PA", - "dial_code": "+507", - }, - { - "name": "Papua Niugini", - "code": "PG", - "dial_code": "+675", - }, - { - "name": "Paraguay", - "code": "PY", - "dial_code": "+595", - }, - { - "name": "Perú", - "code": "PE", - "dial_code": "+51", - }, - { - "name": "Pilipinas", - "code": "PH", - "dial_code": "+63", - }, - { - "name": "Pitcairn Islands", - "code": "PN", - "dial_code": "+64", - }, - { - "name": "Polska", - "code": "PL", - "dial_code": "+48", - }, - { - "name": "Portugal", - "code": "PT", - "dial_code": "+351", - }, - { - "name": "Puerto Rico", - "code": "PR", - "dial_code": "+1939", - }, - { - "name": "Puerto Rico", - "code": "PR", - "dial_code": "+1787", - }, - { - "name": "قطر", - "code": "QA", - "dial_code": "+974", - }, - { - "name": "România", - "code": "RO", - "dial_code": "+40", - }, - { - "name": "Россия", - "code": "RU", - "dial_code": "+7", - }, - { - "name": "Rwanda", - "code": "RW", - "dial_code": "+250", - }, - { - "name": "La Réunion", - "code": "RE", - "dial_code": "+262", - }, - { - "name": "Saint-Barthélemy", - "code": "BL", - "dial_code": "+590", - }, - { - "name": "Saint Helena", - "code": "SH", - "dial_code": "+290", - }, - { - "name": "Saint Kitts and Nevis", - "code": "KN", - "dial_code": "+1869", - }, - { - "name": "Saint Lucia", - "code": "LC", - "dial_code": "+1758", - }, - { - "name": "Saint-Martin", - "code": "MF", - "dial_code": "+590", - }, - { - "name": "Saint-Pierre-et-Miquelon", - "code": "PM", - "dial_code": "+508", - }, - { - "name": "Saint Vincent and the Grenadines", - "code": "VC", - "dial_code": "+1784", - }, - { - "name": "Samoa", - "code": "WS", - "dial_code": "+685", - }, - { - "name": "San Marino", - "code": "SM", - "dial_code": "+378", - }, - { - "name": "São Tomé e Príncipe", - "code": "ST", - "dial_code": "+239", - }, - { - "name": "العربية السعودية", - "code": "SA", - "dial_code": "+966", - }, - { - "name": "Sénégal", - "code": "SN", - "dial_code": "+221", - }, - { - "name": "Србија", - "code": "RS", - "dial_code": "+381", - }, - { - "name": "Seychelles", - "code": "SC", - "dial_code": "+248", - }, - { - "name": "Sierra Leone", - "code": "SL", - "dial_code": "+232", - }, - { - "name": "Singapore", - "code": "SG", - "dial_code": "+65", - }, - { - "name": "Slovensko", - "code": "SK", - "dial_code": "+421", - }, - { - "name": "Slovenija", - "code": "SI", - "dial_code": "+386", - }, - { - "name": "Solomon Islands", - "code": "SB", - "dial_code": "+677", - }, - { - "name": "Soomaaliya", - "code": "SO", - "dial_code": "+252", - }, - { - "name": "South Africa", - "code": "ZA", - "dial_code": "+27", - }, - { - "name": "South Sudan", - "code": "SS", - "dial_code": "+211", - }, - { - "name": "South Georgia", - "code": "GS", - "dial_code": "+500", - }, - { - "name": "España", - "code": "ES", - "dial_code": "+34", - }, - { - "name": "Sri Lanka", - "code": "LK", - "dial_code": "+94", - }, - { - "name": "السودان", - "code": "SD", - "dial_code": "+249", - }, - { - "name": "Suriname", - "code": "SR", - "dial_code": "+597", - }, - { - "name": "Svalbard og Jan Mayen", - "code": "SJ", - "dial_code": "+47", - }, - { - "name": "Swaziland", - "code": "SZ", - "dial_code": "+268", - }, - { - "name": "Sverige", - "code": "SE", - "dial_code": "+46", - }, - { - "name": "Schweiz", - "code": "CH", - "dial_code": "+41", - }, - { - "name": "سوريا", - "code": "SY", - "dial_code": "+963", - }, - { - "name": "臺灣", - "code": "TW", - "dial_code": "+886", - }, - { - "name": "Тоҷикистон", - "code": "TJ", - "dial_code": "+992", - }, - { - "name": "Tanzania", - "code": "TZ", - "dial_code": "+255", - }, - { - "name": "ประเทศไทย", - "code": "TH", - "dial_code": "+66", - }, - { - "name": "Timor-Leste", - "code": "TL", - "dial_code": "+670", - }, - { - "name": "Togo", - "code": "TG", - "dial_code": "+228", - }, - { - "name": "Tokelau", - "code": "TK", - "dial_code": "+690", - }, - { - "name": "Tonga", - "code": "TO", - "dial_code": "+676", - }, - { - "name": "Trinidad and Tobago", - "code": "TT", - "dial_code": "+1868", - }, - { - "name": "تونس", - "code": "TN", - "dial_code": "+216", - }, - { - "name": "Türkiye", - "code": "TR", - "dial_code": "+90", - }, - { - "name": "Türkmenistan", - "code": "TM", - "dial_code": "+993", - }, - { - "name": "Turks and Caicos Islands", - "code": "TC", - "dial_code": "+1649", - }, - { - "name": "Tuvalu", - "code": "TV", - "dial_code": "+688", - }, - { - "name": "Uganda", - "code": "UG", - "dial_code": "+256", - }, - { - "name": "Україна", - "code": "UA", - "dial_code": "+380", - }, - { - "name": "دولة الإمارات العربية المتحدة", - "code": "AE", - "dial_code": "+971", - }, - { - "name": "United Kingdom", - "code": "GB", - "dial_code": "+44", - }, - { - "name": "United States", - "code": "US", - "dial_code": "+1", - }, - { - "name": "Uruguay", - "code": "UY", - "dial_code": "+598", - }, - { - "name": "O‘zbekiston", - "code": "UZ", - "dial_code": "+998", - }, - { - "name": "Vanuatu", - "code": "VU", - "dial_code": "+678", - }, - { - "name": "Venezuela", - "code": "VE", - "dial_code": "+58", - }, - { - "name": "Việt Nam", - "code": "VN", - "dial_code": "+84", - }, - { - "name": "British Virgin Islands", - "code": "VG", - "dial_code": "+1284", - }, - { - "name": "United States Virgin Islands", - "code": "VI", - "dial_code": "+1340", - }, - { - "name": "Wallis et Futuna", - "code": "WF", - "dial_code": "+681", - }, - { - "name": "اليَمَن", - "code": "YE", - "dial_code": "+967", - }, - { - "name": "Zambia", - "code": "ZM", - "dial_code": "+260", - }, - { - "name": "Zimbabwe", - "code": "ZW", - "dial_code": "+263", - }, -]; diff --git a/lib/selection_dialog.dart b/lib/src/bottom_sheet.dart similarity index 86% rename from lib/selection_dialog.dart rename to lib/src/bottom_sheet.dart index 176d0ee2..dcb143c1 100644 --- a/lib/selection_dialog.dart +++ b/lib/src/bottom_sheet.dart @@ -1,9 +1,10 @@ -import 'package:country_code_picker/country_code.dart'; -import 'package:country_code_picker/country_localizations.dart'; import 'package:flutter/material.dart'; -/// selection dialog used for selection of the country code -class SelectionDialog extends StatefulWidget { +import 'country_code.dart'; +import 'country_localizations.dart'; + +/// selection bottom sheet used for selection of the country code +class SelectionBottomSheet extends StatefulWidget { final List elements; final bool? showCountryOnly; final InputDecoration searchDecoration; @@ -18,16 +19,16 @@ class SelectionDialog extends StatefulWidget { final bool hideSearch; final Icon? closeIcon; - /// Background color of SelectionDialog + /// Background color of SelectionBottomSheet final Color? backgroundColor; - /// Boxshaow color of SelectionDialog that matches CountryCodePicker barrier color + /// Boxshaow color of SelectionBottomSheet that matches CountryCodePicker barrier color final Color? barrierColor; /// elements passed as favorite final List favoriteElements; - SelectionDialog( + SelectionBottomSheet( this.elements, this.favoriteElements, { Key? key, @@ -45,16 +46,16 @@ class SelectionDialog extends StatefulWidget { this.barrierColor, this.hideSearch = false, this.closeIcon, - }) : this.searchDecoration = searchDecoration.prefixIcon == null - ? searchDecoration.copyWith(prefixIcon: Icon(Icons.search)) + }) : searchDecoration = searchDecoration.prefixIcon == null + ? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search)) : searchDecoration, super(key: key); @override - State createState() => _SelectionDialogState(); + State createState() => _SelectionBottomSheetState(); } -class _SelectionDialogState extends State { +class _SelectionBottomSheetState extends State { /// this is useful for filtering purpose late List filteredElements; @@ -69,13 +70,14 @@ class _SelectionDialogState extends State { decoration: widget.boxDecoration ?? BoxDecoration( color: widget.backgroundColor ?? Colors.white, - borderRadius: BorderRadius.all(Radius.circular(8.0)), + 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: Offset(0, 3), // changes position of shadow + offset: const Offset(0, 3), // changes position of shadow ), ], ), @@ -137,7 +139,7 @@ class _SelectionDialogState extends State { ); Widget _buildOption(CountryCode e) { - return Container( + return SizedBox( width: 400, child: Flex( direction: Axis.horizontal, diff --git a/lib/src/constants.dart b/lib/src/constants.dart new file mode 100644 index 00000000..9dac0ca4 --- /dev/null +++ b/lib/src/constants.dart @@ -0,0 +1 @@ +enum PickerStyle { dialog, bottomSheet, fullScreen } diff --git a/lib/country_code.dart b/lib/src/country_code.dart similarity index 68% rename from lib/country_code.dart rename to lib/src/country_code.dart index 3d1a6b47..069f0e88 100644 --- a/lib/country_code.dart +++ b/lib/src/country_code.dart @@ -1,12 +1,11 @@ import 'package:collection/collection.dart' show IterableExtension; -import 'package:country_code_picker/country_codes.dart'; -import 'package:country_code_picker/country_localizations.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart' show kDebugMode; -mixin ToAlias {} +import 'country_codes.dart'; +import 'country_localizations.dart'; -@deprecated -class CElement = CountryCode with ToAlias; +mixin ToAlias {} /// Country element. This is the element that contains all the information class CountryCode { @@ -41,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? jsonCode = codes.firstWhereOrNull( (code) => code['dial_code'] == dialCode, @@ -48,10 +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(this.code) ?? this.name; + final nam = CountryLocalizations.of(context)?.translate(code) ?? name; + return this..name = nam ?? name; } factory CountryCode.fromJson(Map json) { diff --git a/lib/src/country_codes.dart b/lib/src/country_codes.dart new file mode 100644 index 00000000..e35a0dd0 --- /dev/null +++ b/lib/src/country_codes.dart @@ -0,0 +1,523 @@ +const List> codes = [ + {"name": "افغانستان", "code": "AF", "iso3Code": "AFG", "dial_code": "+93"}, + {"name": "Åland", "code": "AX", "iso3Code": "ALA", "dial_code": "+358"}, + {"name": "Shqipëria", "code": "AL", "iso3Code": "ALB", "dial_code": "+355"}, + {"name": "الجزائر", "code": "DZ", "iso3Code": "DZA", "dial_code": "+213"}, + { + "name": "American Samoa", + "code": "AS", + "iso3Code": "ASM", + "dial_code": "+1684" + }, + {"name": "Andorra", "code": "AD", "iso3Code": "AND", "dial_code": "+376"}, + {"name": "Angola", "code": "AO", "iso3Code": "AGO", "dial_code": "+244"}, + {"name": "Anguilla", "code": "AI", "iso3Code": "AIA", "dial_code": "+1264"}, + {"name": "Antarctica", "code": "AQ", "iso3Code": "ATA", "dial_code": "+672"}, + { + "name": "Antigua and Barbuda", + "code": "AG", + "iso3Code": "ATG", + "dial_code": "+1268" + }, + {"name": "Argentina", "code": "AR", "iso3Code": "ARG", "dial_code": "+54"}, + {"name": "Հայաստան", "code": "AM", "iso3Code": "ARM", "dial_code": "+374"}, + {"name": "Aruba", "code": "AW", "iso3Code": "ABW", "dial_code": "+297"}, + {"name": "Australia", "code": "AU", "iso3Code": "AUS", "dial_code": "+61"}, + {"name": "Österreich", "code": "AT", "iso3Code": "AUT", "dial_code": "+43"}, + {"name": "Azərbaycan", "code": "AZ", "iso3Code": "AZE", "dial_code": "+994"}, + {"name": "Bahamas", "code": "BS", "iso3Code": "BHS", "dial_code": "+1242"}, + {"name": "‏البحرين", "code": "BH", "iso3Code": "BHR", "dial_code": "+973"}, + {"name": "Bangladesh", "code": "BD", "iso3Code": "BGD", "dial_code": "+880"}, + {"name": "Barbados", "code": "BB", "iso3Code": "BRB", "dial_code": "+1246"}, + {"name": "Белару́сь", "code": "BY", "iso3Code": "BLR", "dial_code": "+375"}, + {"name": "België", "code": "BE", "iso3Code": "BEL", "dial_code": "+32"}, + {"name": "Belize", "code": "BZ", "iso3Code": "BLZ", "dial_code": "+501"}, + {"name": "Bénin", "code": "BJ", "iso3Code": "BEN", "dial_code": "+229"}, + {"name": "Bermuda", "code": "BM", "iso3Code": "BMU", "dial_code": "+1441"}, + {"name": "ʼbrug-yul", "code": "BT", "iso3Code": "BTN", "dial_code": "+975"}, + {"name": "Bolivia", "code": "BO", "iso3Code": "BOL", "dial_code": "+591"}, + { + "name": "Bosna i Hercegovina", + "code": "BA", + "iso3Code": "BIH", + "dial_code": "+387" + }, + {"name": "Botswana", "code": "BW", "iso3Code": "BWA", "dial_code": "+267"}, + {"name": "Bouvetøya", "code": "BV", "iso3Code": "BVT", "dial_code": "+47"}, + {"name": "Brasil", "code": "BR", "iso3Code": "BRA", "dial_code": "+55"}, + { + "name": "British Indian Ocean Territory", + "code": "IO", + "iso3Code": "IOT", + "dial_code": "+246" + }, + { + "name": "Negara Brunei Darussalam", + "code": "BN", + "iso3Code": "BRN", + "dial_code": "+673" + }, + {"name": "България", "code": "BG", "iso3Code": "BGR", "dial_code": "+359"}, + { + "name": "Burkina Faso", + "code": "BF", + "iso3Code": "BFA", + "dial_code": "+226" + }, + {"name": "Burundi", "code": "BI", "iso3Code": "BDI", "dial_code": "+257"}, + {"name": "Cambodia", "code": "KH", "iso3Code": "KHM", "dial_code": "+855"}, + {"name": "Cameroon", "code": "CM", "iso3Code": "CMR", "dial_code": "+237"}, + {"name": "Canada", "code": "CA", "iso3Code": "CAN", "dial_code": "+1"}, + {"name": "Cabo Verde", "code": "CV", "iso3Code": "CPV", "dial_code": "+238"}, + { + "name": "Cayman Islands", + "code": "KY", + "iso3Code": "CYM", + "dial_code": "+1345" + }, + { + "name": "Ködörösêse tî Bêafrîka", + "code": "CF", + "iso3Code": "CAF", + "dial_code": "+236" + }, + {"name": "Tchad", "code": "TD", "iso3Code": "TCD", "dial_code": "+235"}, + {"name": "Chile", "code": "CL", "iso3Code": "CHL", "dial_code": "+56"}, + {"name": "中国大陆", "code": "CN", "iso3Code": "CHN", "dial_code": "+86"}, + { + "name": "Christmas Island", + "code": "CX", + "iso3Code": "CXR", + "dial_code": "+61" + }, + { + "name": "Cocos (Keeling) Islands", + "code": "CC", + "iso3Code": "CCK", + "dial_code": "+61" + }, + {"name": "Colombia", "code": "CO", "iso3Code": "COL", "dial_code": "+57"}, + {"name": "Komori", "code": "KM", "iso3Code": "COM", "dial_code": "+269"}, + { + "name": "République du Congo", + "code": "CG", + "iso3Code": "COG", + "dial_code": "+242" + }, + { + "name": "République démocratique du Congo", + "code": "CD", + "iso3Code": "COD", + "dial_code": "+243" + }, + { + "name": "Cook Islands", + "code": "CK", + "iso3Code": "COK", + "dial_code": "+682" + }, + {"name": "Costa Rica", "code": "CR", "iso3Code": "CRI", "dial_code": "+506"}, + { + "name": "Côte d'Ivoire", + "code": "CI", + "iso3Code": "CIV", + "dial_code": "+225" + }, + {"name": "Hrvatska", "code": "HR", "iso3Code": "HRV", "dial_code": "+385"}, + {"name": "Cuba", "code": "CU", "iso3Code": "CUB", "dial_code": "+53"}, + {"name": "Κύπρος", "code": "CY", "iso3Code": "CYP", "dial_code": "+357"}, + { + "name": "Česká republika", + "code": "CZ", + "iso3Code": "CZE", + "dial_code": "+420" + }, + {"name": "Danmark", "code": "DK", "iso3Code": "DNK", "dial_code": "+45"}, + {"name": "Djibouti", "code": "DJ", "iso3Code": "DJI", "dial_code": "+253"}, + {"name": "Dominica", "code": "DM", "iso3Code": "DMA", "dial_code": "+1767"}, + { + "name": "República Dominicana", + "code": "DO", + "iso3Code": "DOM", + "dial_code": "+1" + }, + {"name": "Ecuador", "code": "EC", "iso3Code": "ECU", "dial_code": "+593"}, + {"name": "مصر‎", "code": "EG", "iso3Code": "EGY", "dial_code": "+20"}, + {"name": "El Salvador", "code": "SV", "iso3Code": "SLV", "dial_code": "+503"}, + { + "name": "Guinea Ecuatorial", + "code": "GQ", + "iso3Code": "GNQ", + "dial_code": "+240" + }, + {"name": "ኤርትራ", "code": "ER", "iso3Code": "ERI", "dial_code": "+291"}, + {"name": "Eesti", "code": "EE", "iso3Code": "EST", "dial_code": "+372"}, + {"name": "ኢትዮጵያ", "code": "ET", "iso3Code": "ETH", "dial_code": "+251"}, + { + "name": "Falkland Islands", + "code": "FK", + "iso3Code": "FLK", + "dial_code": "+500" + }, + {"name": "Føroyar", "code": "FO", "iso3Code": "FRO", "dial_code": "+298"}, + {"name": "Fiji", "code": "FJ", "iso3Code": "FJI", "dial_code": "+679"}, + {"name": "Suomi", "code": "FI", "iso3Code": "FIN", "dial_code": "+358"}, + {"name": "France", "code": "FR", "iso3Code": "FRA", "dial_code": "+33"}, + { + "name": "Guyane française", + "code": "GF", + "iso3Code": "GUF", + "dial_code": "+594" + }, + { + "name": "Polynésie française", + "code": "PF", + "iso3Code": "PYF", + "dial_code": "+689" + }, + { + "name": "Territoire des Terres australes et antarctiques fr", + "code": "TF", + "iso3Code": "ATF", + "dial_code": "+262" + }, + {"name": "Gabon", "code": "GA", "iso3Code": "GAB", "dial_code": "+241"}, + {"name": "Gambia", "code": "GM", "iso3Code": "GMB", "dial_code": "+220"}, + {"name": "საქართველო", "code": "GE", "iso3Code": "GEO", "dial_code": "+995"}, + {"name": "Deutschland", "code": "DE", "iso3Code": "DEU", "dial_code": "+49"}, + {"name": "Ghana", "code": "GH", "iso3Code": "GHA", "dial_code": "+233"}, + {"name": "Gibraltar", "code": "GI", "iso3Code": "GIB", "dial_code": "+350"}, + {"name": "Ελλάδα", "code": "GR", "iso3Code": "GRC", "dial_code": "+30"}, + { + "name": "Kalaallit Nunaat", + "code": "GL", + "iso3Code": "GRL", + "dial_code": "+299" + }, + {"name": "Grenada", "code": "GD", "iso3Code": "GRD", "dial_code": "+1473"}, + {"name": "Guadeloupe", "code": "GP", "iso3Code": "GLP", "dial_code": "+590"}, + {"name": "Guam", "code": "GU", "iso3Code": "GUM", "dial_code": "+1671"}, + {"name": "Guatemala", "code": "GT", "iso3Code": "GTM", "dial_code": "+502"}, + {"name": "Guernsey", "code": "GG", "iso3Code": "GGY", "dial_code": "+44"}, + {"name": "Guinée", "code": "GN", "iso3Code": "GIN", "dial_code": "+224"}, + { + "name": "Guiné-Bissau", + "code": "GW", + "iso3Code": "GNB", + "dial_code": "+245" + }, + {"name": "Guyana", "code": "GY", "iso3Code": "GUY", "dial_code": "+592"}, + {"name": "Haïti", "code": "HT", "iso3Code": "HTI", "dial_code": "+509"}, + { + "name": "Heard Island and McDonald Islands", + "code": "HM", + "iso3Code": "HMD", + "dial_code": "+0" + }, + {"name": "Vaticano", "code": "VA", "iso3Code": "VAT", "dial_code": "+379"}, + {"name": "Honduras", "code": "HN", "iso3Code": "HND", "dial_code": "+504"}, + {"name": "中國香港", "code": "HK", "iso3Code": "HKG", "dial_code": "+852"}, + {"name": "Magyarország", "code": "HU", "iso3Code": "HUN", "dial_code": "+36"}, + {"name": "Ísland", "code": "IS", "iso3Code": "ISL", "dial_code": "+354"}, + {"name": "भारत", "code": "IN", "iso3Code": "IND", "dial_code": "+91"}, + {"name": "Indonesia", "code": "ID", "iso3Code": "IDN", "dial_code": "+62"}, + {"name": "ایران", "code": "IR", "iso3Code": "IRN", "dial_code": "+98"}, + {"name": "العراق", "code": "IQ", "iso3Code": "IRQ", "dial_code": "+964"}, + {"name": "Éire", "code": "IE", "iso3Code": "IRL", "dial_code": "+353"}, + {"name": "Isle of Man", "code": "IM", "iso3Code": "IMN", "dial_code": "+44"}, + {"name": "ישראל", "code": "IL", "iso3Code": "ISR", "dial_code": "+972"}, + {"name": "Italia", "code": "IT", "iso3Code": "ITA", "dial_code": "+39"}, + {"name": "Jamaica", "code": "JM", "iso3Code": "JAM", "dial_code": "+1876"}, + {"name": "日本", "code": "JP", "iso3Code": "JPN", "dial_code": "+81"}, + {"name": "Jersey", "code": "JE", "iso3Code": "JEY", "dial_code": "+44"}, + {"name": "الأردن", "code": "JO", "iso3Code": "JOR", "dial_code": "+962"}, + {"name": "Қазақстан", "code": "KZ", "iso3Code": "KAZ", "dial_code": "+7"}, + {"name": "Kenya", "code": "KE", "iso3Code": "KEN", "dial_code": "+254"}, + {"name": "Kiribati", "code": "KI", "iso3Code": "KIR", "dial_code": "+686"}, + {"name": "북한", "code": "KP", "iso3Code": "PRK", "dial_code": "+850"}, + {"name": "대한민국", "code": "KR", "iso3Code": "KOR", "dial_code": "+82"}, + { + "name": "Republika e Kosovës", + "code": "XK", + "iso3Code": "KOS", + "dial_code": "+383" + }, + {"name": "الكويت", "code": "KW", "iso3Code": "KWT", "dial_code": "+965"}, + {"name": "Кыргызстан", "code": "KG", "iso3Code": "KGZ", "dial_code": "+996"}, + {"name": "ສປປລາວ", "code": "LA", "iso3Code": "LAO", "dial_code": "+856"}, + {"name": "Latvija", "code": "LV", "iso3Code": "LVA", "dial_code": "+371"}, + {"name": "لبنان", "code": "LB", "iso3Code": "LBN", "dial_code": "+961"}, + {"name": "Lesotho", "code": "LS", "iso3Code": "LSO", "dial_code": "+266"}, + {"name": "Liberia", "code": "LR", "iso3Code": "LBR", "dial_code": "+231"}, + {"name": "‏ليبيا", "code": "LY", "iso3Code": "LBY", "dial_code": "+218"}, + { + "name": "Liechtenstein", + "code": "LI", + "iso3Code": "LIE", + "dial_code": "+423" + }, + {"name": "Lietuva", "code": "LT", "iso3Code": "LTU", "dial_code": "+370"}, + {"name": "Luxembourg", "code": "LU", "iso3Code": "LUX", "dial_code": "+352"}, + {"name": "中國澳門", "code": "MO", "iso3Code": "MAC", "dial_code": "+853"}, + {"name": "Македонија", "code": "MK", "iso3Code": "MKD", "dial_code": "+389"}, + { + "name": "Madagasikara", + "code": "MG", + "iso3Code": "MDG", + "dial_code": "+261" + }, + {"name": "Malawi", "code": "MW", "iso3Code": "MWI", "dial_code": "+265"}, + {"name": "Malaysia", "code": "MY", "iso3Code": "MYS", "dial_code": "+60"}, + {"name": "Maldives", "code": "MV", "iso3Code": "MDV", "dial_code": "+960"}, + {"name": "Mali", "code": "ML", "iso3Code": "MLI", "dial_code": "+223"}, + {"name": "Malta", "code": "MT", "iso3Code": "MLT", "dial_code": "+356"}, + {"name": "M̧ajeļ", "code": "MH", "iso3Code": "MHL", "dial_code": "+692"}, + {"name": "Martinique", "code": "MQ", "iso3Code": "MTQ", "dial_code": "+596"}, + {"name": "موريتانيا", "code": "MR", "iso3Code": "MRT", "dial_code": "+222"}, + {"name": "Maurice", "code": "MU", "iso3Code": "MUS", "dial_code": "+230"}, + {"name": "Mayotte", "code": "YT", "iso3Code": "MYT", "dial_code": "+262"}, + {"name": "México", "code": "MX", "iso3Code": "MEX", "dial_code": "+52"}, + {"name": "Micronesia", "code": "FM", "iso3Code": "FSM", "dial_code": "+691"}, + {"name": "Moldova", "code": "MD", "iso3Code": "MDA", "dial_code": "+373"}, + {"name": "Monaco", "code": "MC", "iso3Code": "MCO", "dial_code": "+377"}, + {"name": "Монгол улс", "code": "MN", "iso3Code": "MNG", "dial_code": "+976"}, + {"name": "Црна Гора", "code": "ME", "iso3Code": "MNE", "dial_code": "+382"}, + {"name": "Montserrat", "code": "MS", "iso3Code": "MSR", "dial_code": "+1664"}, + {"name": "المغرب", "code": "MA", "iso3Code": "MAR", "dial_code": "+212"}, + {"name": "Moçambique", "code": "MZ", "iso3Code": "MOZ", "dial_code": "+258"}, + {"name": "Myanmar", "code": "MM", "iso3Code": "MMR", "dial_code": "+95"}, + {"name": "Namibia", "code": "NA", "iso3Code": "NAM", "dial_code": "+264"}, + {"name": "Nauru", "code": "NR", "iso3Code": "NRU", "dial_code": "+674"}, + {"name": "नेपाल", "code": "NP", "iso3Code": "NPL", "dial_code": "+977"}, + {"name": "Nederland", "code": "NL", "iso3Code": "NLD", "dial_code": "+31"}, + { + "name": "Nouvelle-Calédonie", + "code": "NC", + "iso3Code": "NCL", + "dial_code": "+687" + }, + {"name": "New Zealand", "code": "NZ", "iso3Code": "NZL", "dial_code": "+64"}, + {"name": "Nicaragua", "code": "NI", "iso3Code": "NIC", "dial_code": "+505"}, + {"name": "Niger", "code": "NE", "iso3Code": "NER", "dial_code": "+227"}, + {"name": "Nigeria", "code": "NG", "iso3Code": "NGA", "dial_code": "+234"}, + {"name": "Niuē", "code": "NU", "iso3Code": "NIU", "dial_code": "+683"}, + { + "name": "Norfolk Island", + "code": "NF", + "iso3Code": "NFK", + "dial_code": "+672" + }, + { + "name": "Northern Mariana Islands", + "code": "MP", + "iso3Code": "MNP", + "dial_code": "+1670" + }, + {"name": "Norge", "code": "NO", "iso3Code": "NOR", "dial_code": "+47"}, + {"name": "عمان", "code": "OM", "iso3Code": "OMN", "dial_code": "+968"}, + {"name": "Pakistan", "code": "PK", "iso3Code": "PAK", "dial_code": "+92"}, + {"name": "Palau", "code": "PW", "iso3Code": "PLW", "dial_code": "+680"}, + {"name": "فلسطين", "code": "PS", "iso3Code": "PSE", "dial_code": "+970"}, + {"name": "Panamá", "code": "PA", "iso3Code": "PAN", "dial_code": "+507"}, + { + "name": "Papua Niugini", + "code": "PG", + "iso3Code": "PNG", + "dial_code": "+675" + }, + {"name": "Paraguay", "code": "PY", "iso3Code": "PRY", "dial_code": "+595"}, + {"name": "Perú", "code": "PE", "iso3Code": "PER", "dial_code": "+51"}, + {"name": "Pilipinas", "code": "PH", "iso3Code": "PHL", "dial_code": "+63"}, + { + "name": "Pitcairn Islands", + "code": "PN", + "iso3Code": "PCN", + "dial_code": "+64" + }, + {"name": "Polska", "code": "PL", "iso3Code": "POL", "dial_code": "+48"}, + {"name": "Portugal", "code": "PT", "iso3Code": "PRT", "dial_code": "+351"}, + { + "name": "Puerto Rico", + "code": "PR", + "iso3Code": "PRI", + "dial_code": "+1939" + }, + { + "name": "Puerto Rico", + "code": "PR", + "iso3Code": "PRI", + "dial_code": "+1787" + }, + {"name": "قطر", "code": "QA", "iso3Code": "QAT", "dial_code": "+974"}, + {"name": "România", "code": "RO", "iso3Code": "ROU", "dial_code": "+40"}, + {"name": "Россия", "code": "RU", "iso3Code": "RUS", "dial_code": "+7"}, + {"name": "Rwanda", "code": "RW", "iso3Code": "RWA", "dial_code": "+250"}, + {"name": "La Réunion", "code": "RE", "iso3Code": "REU", "dial_code": "+262"}, + { + "name": "Saint-Barthélemy", + "code": "BL", + "iso3Code": "BLM", + "dial_code": "+590" + }, + { + "name": "Saint Helena", + "code": "SH", + "iso3Code": "SHN", + "dial_code": "+290" + }, + { + "name": "Saint Kitts and Nevis", + "code": "KN", + "iso3Code": "KNA", + "dial_code": "+1869" + }, + { + "name": "Saint Lucia", + "code": "LC", + "iso3Code": "LCA", + "dial_code": "+1758" + }, + { + "name": "Saint-Martin", + "code": "MF", + "iso3Code": "MAF", + "dial_code": "+590" + }, + { + "name": "Saint-Pierre-et-Miquelon", + "code": "PM", + "iso3Code": "SPM", + "dial_code": "+508" + }, + { + "name": "Saint Vincent and the Grenadines", + "code": "VC", + "iso3Code": "VCT", + "dial_code": "+1784" + }, + {"name": "Samoa", "code": "WS", "iso3Code": "WSM", "dial_code": "+685"}, + {"name": "San Marino", "code": "SM", "iso3Code": "SMR", "dial_code": "+378"}, + { + "name": "São Tomé e Príncipe", + "code": "ST", + "iso3Code": "STP", + "dial_code": "+239" + }, + { + "name": "العربية السعودية", + "code": "SA", + "iso3Code": "SAU", + "dial_code": "+966" + }, + {"name": "Sénégal", "code": "SN", "iso3Code": "SEN", "dial_code": "+221"}, + {"name": "Србија", "code": "RS", "iso3Code": "SRB", "dial_code": "+381"}, + {"name": "Seychelles", "code": "SC", "iso3Code": "SYC", "dial_code": "+248"}, + { + "name": "Sierra Leone", + "code": "SL", + "iso3Code": "SLE", + "dial_code": "+232" + }, + {"name": "Singapore", "code": "SG", "iso3Code": "SGP", "dial_code": "+65"}, + {"name": "Slovensko", "code": "SK", "iso3Code": "SVK", "dial_code": "+421"}, + {"name": "Slovenija", "code": "SI", "iso3Code": "SVN", "dial_code": "+386"}, + { + "name": "Solomon Islands", + "code": "SB", + "iso3Code": "SLB", + "dial_code": "+677" + }, + {"name": "Soomaaliya", "code": "SO", "iso3Code": "SOM", "dial_code": "+252"}, + {"name": "South Africa", "code": "ZA", "iso3Code": "ZAF", "dial_code": "+27"}, + {"name": "South Sudan", "code": "SS", "iso3Code": "SSD", "dial_code": "+211"}, + { + "name": "South Georgia", + "code": "GS", + "iso3Code": "SGS", + "dial_code": "+500" + }, + {"name": "España", "code": "ES", "iso3Code": "ESP", "dial_code": "+34"}, + {"name": "Sri Lanka", "code": "LK", "iso3Code": "LKA", "dial_code": "+94"}, + {"name": "السودان", "code": "SD", "iso3Code": "SDN", "dial_code": "+249"}, + {"name": "Suriname", "code": "SR", "iso3Code": "SUR", "dial_code": "+597"}, + { + "name": "Svalbard og Jan Mayen", + "code": "SJ", + "iso3Code": "SJM", + "dial_code": "+47" + }, + {"name": "Swaziland", "code": "SZ", "iso3Code": "SWZ", "dial_code": "+268"}, + {"name": "Sverige", "code": "SE", "iso3Code": "SWE", "dial_code": "+46"}, + {"name": "Schweiz", "code": "CH", "iso3Code": "CHE", "dial_code": "+41"}, + {"name": "سوريا", "code": "SY", "iso3Code": "SYR", "dial_code": "+963"}, + {"name": "中國臺灣", "code": "TW", "iso3Code": "TWN", "dial_code": "+886"}, + {"name": "Тоҷикистон", "code": "TJ", "iso3Code": "TJK", "dial_code": "+992"}, + {"name": "Tanzania", "code": "TZ", "iso3Code": "TZA", "dial_code": "+255"}, + {"name": "ประเทศไทย", "code": "TH", "iso3Code": "THA", "dial_code": "+66"}, + {"name": "Timor-Leste", "code": "TL", "iso3Code": "TLS", "dial_code": "+670"}, + {"name": "Togo", "code": "TG", "iso3Code": "TGO", "dial_code": "+228"}, + {"name": "Tokelau", "code": "TK", "iso3Code": "TKL", "dial_code": "+690"}, + {"name": "Tonga", "code": "TO", "iso3Code": "TON", "dial_code": "+676"}, + { + "name": "Trinidad and Tobago", + "code": "TT", + "iso3Code": "TTO", + "dial_code": "+1868" + }, + {"name": "تونس", "code": "TN", "iso3Code": "TUN", "dial_code": "+216"}, + {"name": "Türkiye", "code": "TR", "iso3Code": "TUR", "dial_code": "+90"}, + { + "name": "Türkmenistan", + "code": "TM", + "iso3Code": "TKM", + "dial_code": "+993" + }, + { + "name": "Turks and Caicos Islands", + "code": "TC", + "iso3Code": "TCA", + "dial_code": "+1649" + }, + {"name": "Tuvalu", "code": "TV", "iso3Code": "TUV", "dial_code": "+688"}, + {"name": "Uganda", "code": "UG", "iso3Code": "UGA", "dial_code": "+256"}, + {"name": "Україна", "code": "UA", "iso3Code": "UKR", "dial_code": "+380"}, + { + "name": "دولة الإمارات العربية المتحدة", + "code": "AE", + "iso3Code": "ARE", + "dial_code": "+971" + }, + { + "name": "United Kingdom", + "code": "GB", + "iso3Code": "GBR", + "dial_code": "+44" + }, + {"name": "United States", "code": "US", "iso3Code": "USA", "dial_code": "+1"}, + {"name": "Uruguay", "code": "UY", "iso3Code": "URY", "dial_code": "+598"}, + {"name": "O‘zbekiston", "code": "UZ", "iso3Code": "UZB", "dial_code": "+998"}, + {"name": "Vanuatu", "code": "VU", "iso3Code": "VUT", "dial_code": "+678"}, + {"name": "Venezuela", "code": "VE", "iso3Code": "VEN", "dial_code": "+58"}, + {"name": "Việt Nam", "code": "VN", "iso3Code": "VNM", "dial_code": "+84"}, + { + "name": "British Virgin Islands", + "code": "VG", + "iso3Code": "VGB", + "dial_code": "+1284" + }, + { + "name": "United States Virgin Islands", + "code": "VI", + "iso3Code": "VIR", + "dial_code": "+1340" + }, + { + "name": "Wallis et Futuna", + "code": "WF", + "iso3Code": "WLF", + "dial_code": "+681" + }, + {"name": "اليَمَن", "code": "YE", "iso3Code": "YEM", "dial_code": "+967"}, + {"name": "Zambia", "code": "ZM", "iso3Code": "ZMB", "dial_code": "+260"}, + {"name": "Zimbabwe", "code": "ZW", "iso3Code": "ZWE", "dial_code": "+263"} +]; diff --git a/lib/country_localizations.dart b/lib/src/country_localizations.dart similarity index 70% rename from lib/country_localizations.dart rename to lib/src/country_localizations.dart index 3020f78e..f0bceac6 100644 --- a/lib/country_localizations.dart +++ b/lib/src/country_localizations.dart @@ -15,14 +15,17 @@ class CountryLocalizations { ); } - static const LocalizationsDelegate delegate = - _CountryLocalizationsDelegate(); + static const LocalizationsDelegate delegate = _CountryLocalizationsDelegate(); + + static LocalizationsDelegate getDelegate({bool enableLocalization = true}) { + return _CountryLocalizationsDelegate(enableLocalization: enableLocalization); + } late Map _localizedStrings; Future load() async { - String jsonString = await rootBundle.loadString( - 'packages/country_code_picker/i18n/${locale.languageCode}.json'); + String jsonString = + await rootBundle.loadString('packages/country_code_picker/src/i18n/${locale.languageCode}.json'); Map jsonMap = json.decode(jsonString); _localizedStrings = jsonMap.map((key, value) { @@ -37,9 +40,10 @@ class CountryLocalizations { } } -class _CountryLocalizationsDelegate - extends LocalizationsDelegate { - const _CountryLocalizationsDelegate(); +class _CountryLocalizationsDelegate extends LocalizationsDelegate { + final bool enableLocalization; + + const _CountryLocalizationsDelegate({this.enableLocalization = true}); @override bool isSupported(Locale locale) { @@ -119,7 +123,10 @@ class _CountryLocalizationsDelegate @override Future load(Locale locale) async { - CountryLocalizations localizations = new 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; } diff --git a/lib/i18n/af.json b/lib/src/i18n/af.json similarity index 100% rename from lib/i18n/af.json rename to lib/src/i18n/af.json diff --git a/lib/i18n/am.json b/lib/src/i18n/am.json similarity index 100% rename from lib/i18n/am.json rename to lib/src/i18n/am.json diff --git a/lib/i18n/ar.json b/lib/src/i18n/ar.json similarity index 100% rename from lib/i18n/ar.json rename to lib/src/i18n/ar.json diff --git a/lib/i18n/az.json b/lib/src/i18n/az.json similarity index 100% rename from lib/i18n/az.json rename to lib/src/i18n/az.json diff --git a/lib/i18n/be.json b/lib/src/i18n/be.json similarity index 100% rename from lib/i18n/be.json rename to lib/src/i18n/be.json diff --git a/lib/i18n/bg.json b/lib/src/i18n/bg.json similarity index 100% rename from lib/i18n/bg.json rename to lib/src/i18n/bg.json diff --git a/lib/i18n/bn.json b/lib/src/i18n/bn.json similarity index 100% rename from lib/i18n/bn.json rename to lib/src/i18n/bn.json diff --git a/lib/i18n/bs.json b/lib/src/i18n/bs.json similarity index 100% rename from lib/i18n/bs.json rename to lib/src/i18n/bs.json diff --git a/lib/i18n/ca.json b/lib/src/i18n/ca.json similarity index 100% rename from lib/i18n/ca.json rename to lib/src/i18n/ca.json diff --git a/lib/i18n/cs.json b/lib/src/i18n/cs.json similarity index 100% rename from lib/i18n/cs.json rename to lib/src/i18n/cs.json diff --git a/lib/i18n/da.json b/lib/src/i18n/da.json similarity index 100% rename from lib/i18n/da.json rename to lib/src/i18n/da.json diff --git a/lib/i18n/de.json b/lib/src/i18n/de.json similarity index 100% rename from lib/i18n/de.json rename to lib/src/i18n/de.json diff --git a/lib/i18n/el.json b/lib/src/i18n/el.json similarity index 100% rename from lib/i18n/el.json rename to lib/src/i18n/el.json diff --git a/lib/i18n/en.json b/lib/src/i18n/en.json similarity index 97% rename from lib/i18n/en.json rename to lib/src/i18n/en.json index 68e89d86..62f6b855 100644 --- a/lib/i18n/en.json +++ b/lib/src/i18n/en.json @@ -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", diff --git a/lib/i18n/es.json b/lib/src/i18n/es.json similarity index 100% rename from lib/i18n/es.json rename to lib/src/i18n/es.json diff --git a/lib/i18n/et.json b/lib/src/i18n/et.json similarity index 100% rename from lib/i18n/et.json rename to lib/src/i18n/et.json diff --git a/lib/i18n/fa.json b/lib/src/i18n/fa.json similarity index 100% rename from lib/i18n/fa.json rename to lib/src/i18n/fa.json diff --git a/lib/i18n/fi.json b/lib/src/i18n/fi.json similarity index 100% rename from lib/i18n/fi.json rename to lib/src/i18n/fi.json diff --git a/lib/i18n/fr.json b/lib/src/i18n/fr.json similarity index 92% rename from lib/i18n/fr.json rename to lib/src/i18n/fr.json index e7ea4d02..d1a919be 100644 --- a/lib/i18n/fr.json +++ b/lib/src/i18n/fr.json @@ -18,7 +18,7 @@ "BH": "Bahrein", "BD": "Bangladesh", "BB": "Barbade", - "BY": "Bielorussie", + "BY": "Biélorussie", "BE": "Belgique", "BZ": "Belize", "BJ": "Bénin", @@ -38,8 +38,8 @@ "CM": "Cameroun", "CA": "Canada", "CV": "Cap-Vert", - "KY": "Caïmanes", - "CF": "Centrafricaine, République", + "KY": "Îles Caïmans", + "CF": "République Centrafricaine", "TD": "Tchad", "CL": "Chili", "CN": "Chine", @@ -83,7 +83,7 @@ "GI": "Gibraltar", "GR": "Grèce", "GL": "Groenland", - "GD": "Grenada", + "GD": "Grenade", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", @@ -92,7 +92,7 @@ "GY": "Guyana", "HT": "Haïti", "HM": "Îles Heard-et-MacDonald", - "VA": "Saint-Siège", + "VA": "Vatican", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hongrie", @@ -110,10 +110,10 @@ "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", - "KG": "Kirghistan", + "KP": "Corée du Nord", + "KR": "Corée du Sud", + "KW": "Koweït", + "KG": "Kirghizistan", "LA": "Laos", "LV": "Lettonie", "LB": "Liban", @@ -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,19 +200,19 @@ "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", - "TT": "Trinidad et Tobago", + "TT": "Trinité-et-Tobago", "TN": "Tunisie", "TR": "Turquie", "TM": "Turkménistan", diff --git a/lib/i18n/gl.json b/lib/src/i18n/gl.json similarity index 100% rename from lib/i18n/gl.json rename to lib/src/i18n/gl.json diff --git a/lib/i18n/ha.json b/lib/src/i18n/ha.json similarity index 100% rename from lib/i18n/ha.json rename to lib/src/i18n/ha.json diff --git a/lib/i18n/he.json b/lib/src/i18n/he.json similarity index 100% rename from lib/i18n/he.json rename to lib/src/i18n/he.json diff --git a/lib/i18n/hi.json b/lib/src/i18n/hi.json similarity index 100% rename from lib/i18n/hi.json rename to lib/src/i18n/hi.json diff --git a/lib/i18n/hr.json b/lib/src/i18n/hr.json similarity index 100% rename from lib/i18n/hr.json rename to lib/src/i18n/hr.json diff --git a/lib/i18n/hu.json b/lib/src/i18n/hu.json similarity index 100% rename from lib/i18n/hu.json rename to lib/src/i18n/hu.json diff --git a/lib/i18n/hy.json b/lib/src/i18n/hy.json similarity index 100% rename from lib/i18n/hy.json rename to lib/src/i18n/hy.json diff --git a/lib/i18n/id.json b/lib/src/i18n/id.json similarity index 100% rename from lib/i18n/id.json rename to lib/src/i18n/id.json diff --git a/lib/i18n/is.json b/lib/src/i18n/is.json similarity index 100% rename from lib/i18n/is.json rename to lib/src/i18n/is.json diff --git a/lib/i18n/it.json b/lib/src/i18n/it.json similarity index 100% rename from lib/i18n/it.json rename to lib/src/i18n/it.json diff --git a/lib/i18n/ja.json b/lib/src/i18n/ja.json similarity index 100% rename from lib/i18n/ja.json rename to lib/src/i18n/ja.json diff --git a/lib/i18n/ka.json b/lib/src/i18n/ka.json similarity index 100% rename from lib/i18n/ka.json rename to lib/src/i18n/ka.json diff --git a/lib/i18n/kk.json b/lib/src/i18n/kk.json similarity index 100% rename from lib/i18n/kk.json rename to lib/src/i18n/kk.json diff --git a/lib/i18n/km.json b/lib/src/i18n/km.json similarity index 100% rename from lib/i18n/km.json rename to lib/src/i18n/km.json diff --git a/lib/i18n/ko.json b/lib/src/i18n/ko.json similarity index 100% rename from lib/i18n/ko.json rename to lib/src/i18n/ko.json diff --git a/lib/i18n/ku.json b/lib/src/i18n/ku.json similarity index 100% rename from lib/i18n/ku.json rename to lib/src/i18n/ku.json diff --git a/lib/i18n/ky.json b/lib/src/i18n/ky.json similarity index 100% rename from lib/i18n/ky.json rename to lib/src/i18n/ky.json diff --git a/lib/i18n/lt.json b/lib/src/i18n/lt.json similarity index 100% rename from lib/i18n/lt.json rename to lib/src/i18n/lt.json diff --git a/lib/i18n/lv.json b/lib/src/i18n/lv.json similarity index 100% rename from lib/i18n/lv.json rename to lib/src/i18n/lv.json diff --git a/lib/i18n/mk.json b/lib/src/i18n/mk.json similarity index 100% rename from lib/i18n/mk.json rename to lib/src/i18n/mk.json diff --git a/lib/i18n/ml.json b/lib/src/i18n/ml.json similarity index 100% rename from lib/i18n/ml.json rename to lib/src/i18n/ml.json diff --git a/lib/i18n/mn.json b/lib/src/i18n/mn.json similarity index 100% rename from lib/i18n/mn.json rename to lib/src/i18n/mn.json diff --git a/lib/i18n/ms.json b/lib/src/i18n/ms.json similarity index 100% rename from lib/i18n/ms.json rename to lib/src/i18n/ms.json diff --git a/lib/i18n/nb.json b/lib/src/i18n/nb.json similarity index 100% rename from lib/i18n/nb.json rename to lib/src/i18n/nb.json diff --git a/lib/i18n/nl.json b/lib/src/i18n/nl.json similarity index 100% rename from lib/i18n/nl.json rename to lib/src/i18n/nl.json diff --git a/lib/i18n/nn.json b/lib/src/i18n/nn.json similarity index 100% rename from lib/i18n/nn.json rename to lib/src/i18n/nn.json diff --git a/lib/i18n/no.json b/lib/src/i18n/no.json similarity index 100% rename from lib/i18n/no.json rename to lib/src/i18n/no.json diff --git a/lib/i18n/pl.json b/lib/src/i18n/pl.json similarity index 100% rename from lib/i18n/pl.json rename to lib/src/i18n/pl.json diff --git a/lib/i18n/ps.json b/lib/src/i18n/ps.json similarity index 100% rename from lib/i18n/ps.json rename to lib/src/i18n/ps.json diff --git a/lib/i18n/pt.json b/lib/src/i18n/pt.json similarity index 100% rename from lib/i18n/pt.json rename to lib/src/i18n/pt.json diff --git a/lib/i18n/ro.json b/lib/src/i18n/ro.json similarity index 100% rename from lib/i18n/ro.json rename to lib/src/i18n/ro.json diff --git a/lib/i18n/ru.json b/lib/src/i18n/ru.json similarity index 100% rename from lib/i18n/ru.json rename to lib/src/i18n/ru.json diff --git a/lib/i18n/sd.json b/lib/src/i18n/sd.json similarity index 100% rename from lib/i18n/sd.json rename to lib/src/i18n/sd.json diff --git a/lib/i18n/sk.json b/lib/src/i18n/sk.json similarity index 100% rename from lib/i18n/sk.json rename to lib/src/i18n/sk.json diff --git a/lib/i18n/sl.json b/lib/src/i18n/sl.json similarity index 100% rename from lib/i18n/sl.json rename to lib/src/i18n/sl.json diff --git a/lib/i18n/so.json b/lib/src/i18n/so.json similarity index 100% rename from lib/i18n/so.json rename to lib/src/i18n/so.json diff --git a/lib/i18n/sq.json b/lib/src/i18n/sq.json similarity index 100% rename from lib/i18n/sq.json rename to lib/src/i18n/sq.json diff --git a/lib/i18n/sr.json b/lib/src/i18n/sr.json similarity index 100% rename from lib/i18n/sr.json rename to lib/src/i18n/sr.json diff --git a/lib/i18n/sv.json b/lib/src/i18n/sv.json similarity index 100% rename from lib/i18n/sv.json rename to lib/src/i18n/sv.json diff --git a/lib/i18n/ta.json b/lib/src/i18n/ta.json similarity index 100% rename from lib/i18n/ta.json rename to lib/src/i18n/ta.json diff --git a/lib/i18n/tg.json b/lib/src/i18n/tg.json similarity index 100% rename from lib/i18n/tg.json rename to lib/src/i18n/tg.json diff --git a/lib/i18n/th.json b/lib/src/i18n/th.json similarity index 100% rename from lib/i18n/th.json rename to lib/src/i18n/th.json diff --git a/lib/i18n/tr.json b/lib/src/i18n/tr.json similarity index 100% rename from lib/i18n/tr.json rename to lib/src/i18n/tr.json diff --git a/lib/i18n/tt.json b/lib/src/i18n/tt.json similarity index 100% rename from lib/i18n/tt.json rename to lib/src/i18n/tt.json diff --git a/lib/i18n/ug.json b/lib/src/i18n/ug.json similarity index 100% rename from lib/i18n/ug.json rename to lib/src/i18n/ug.json diff --git a/lib/i18n/uk.json b/lib/src/i18n/uk.json similarity index 100% rename from lib/i18n/uk.json rename to lib/src/i18n/uk.json diff --git a/lib/i18n/ur.json b/lib/src/i18n/ur.json similarity index 100% rename from lib/i18n/ur.json rename to lib/src/i18n/ur.json diff --git a/lib/i18n/uz.json b/lib/src/i18n/uz.json similarity index 100% rename from lib/i18n/uz.json rename to lib/src/i18n/uz.json diff --git a/lib/i18n/vi.json b/lib/src/i18n/vi.json similarity index 100% rename from lib/i18n/vi.json rename to lib/src/i18n/vi.json diff --git a/lib/i18n/zh.json b/lib/src/i18n/zh.json similarity index 98% rename from lib/i18n/zh.json rename to lib/src/i18n/zh.json index 93abba2a..2f1c941f 100644 --- a/lib/i18n/zh.json +++ b/lib/src/i18n/zh.json @@ -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": "乌干达", diff --git a/lib/src/selection_dialog.dart b/lib/src/selection_dialog.dart new file mode 100644 index 00000000..6a12d6dd --- /dev/null +++ b/lib/src/selection_dialog.dart @@ -0,0 +1,253 @@ +import 'package:flutter/material.dart'; +import 'package:diacritic/diacritic.dart'; + +import 'country_code.dart'; +import 'country_localizations.dart'; + +/// selection dialog used for selection of the country code +class SelectionDialog extends StatefulWidget { + final List elements; + 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; + final double flagWidth; + 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; + + /// Boxshaow color of SelectionDialog that matches CountryCodePicker barrier color + final Color? barrierColor; + + /// elements passed as favorite + final List 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, + this.flagWidth = 32, + this.size, + 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, + super(key: key); + + @override + State createState() => _SelectionDialogState(); +} + +class _SelectionDialogState extends State { + /// this is useful for filtering purpose + late List 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: [ + 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: widget.searchPadding, + child: TextField( + autofocus: widget.isFocused ?? false, + 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) => InkWell( + onTap: () { + _selectItem(f); + }, + child: Padding( + padding: widget.dialogItemPadding, + child: _buildOption(f), + ))), + const Divider(), + ], + ), + if (filteredElements.isEmpty) + _buildEmptySearchWidget(context) + else + ...filteredElements.map((e) => InkWell( + onTap: () { + _selectItem(e); + }, + child: Padding( + padding: widget.dialogItemPadding, + child: _buildOption(e), + ))), + ], + ), + ), + ], + ), + ), + ); + + Widget _buildOption(CountryCode e) { + return SizedBox( + width: 400, + child: Flex( + direction: Axis.horizontal, + children: [ + if (widget.showFlag!) + Flexible( + child: Container( + 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, + 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) { + final normalizedSearch = removeDiacritics(s.toUpperCase()); + setState(() { + filteredElements = widget.elements + .where((e) => + e.code!.contains(normalizedSearch) || + e.dialCode!.contains(normalizedSearch) || + removeDiacritics(e.name!.toUpperCase()) + .contains(normalizedSearch)) + .toList(); + }); + } + + void _selectItem(CountryCode e) { + Navigator.pop(context, e); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index b0c5ab80..f474c187 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,89 +1,92 @@ 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: 2.0.2 -homepage: https://github.com/imtoori/CountryCodePicker +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.4.1 +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 - - modal_bottom_sheet: ^2.0.0 collection: ^1.15.0 - universal_platform: ^1.0.0+1 + diacritic: ^0.1.5 flutter: assets: - flags/ - - packages/country_code_picker/i18n/af.json - - packages/country_code_picker/i18n/am.json - - packages/country_code_picker/i18n/ha.json - - packages/country_code_picker/i18n/ku.json - - packages/country_code_picker/i18n/ml.json - - packages/country_code_picker/i18n/no.json - - packages/country_code_picker/i18n/ps.json - - packages/country_code_picker/i18n/sd.json - - packages/country_code_picker/i18n/so.json - - packages/country_code_picker/i18n/sq.json - - packages/country_code_picker/i18n/ta.json - - packages/country_code_picker/i18n/tg.json - - packages/country_code_picker/i18n/tt.json - - packages/country_code_picker/i18n/ug.json - - packages/country_code_picker/i18n/ur.json - - packages/country_code_picker/i18n/vi.json - - packages/country_code_picker/i18n/ar.json - - packages/country_code_picker/i18n/az.json - - packages/country_code_picker/i18n/be.json - - packages/country_code_picker/i18n/bg.json - - packages/country_code_picker/i18n/bn.json - - packages/country_code_picker/i18n/bs.json - - packages/country_code_picker/i18n/ca.json - - packages/country_code_picker/i18n/cs.json - - packages/country_code_picker/i18n/da.json - - packages/country_code_picker/i18n/de.json - - packages/country_code_picker/i18n/el.json - - packages/country_code_picker/i18n/en.json - - packages/country_code_picker/i18n/es.json - - packages/country_code_picker/i18n/et.json - - packages/country_code_picker/i18n/fa.json - - packages/country_code_picker/i18n/fi.json - - packages/country_code_picker/i18n/fr.json - - packages/country_code_picker/i18n/gl.json - - packages/country_code_picker/i18n/el.json - - packages/country_code_picker/i18n/he.json - - packages/country_code_picker/i18n/hi.json - - packages/country_code_picker/i18n/hr.json - - packages/country_code_picker/i18n/hu.json - - packages/country_code_picker/i18n/hy.json - - packages/country_code_picker/i18n/id.json - - packages/country_code_picker/i18n/is.json - - packages/country_code_picker/i18n/it.json - - packages/country_code_picker/i18n/ja.json - - packages/country_code_picker/i18n/ka.json - - packages/country_code_picker/i18n/kk.json - - packages/country_code_picker/i18n/km.json - - packages/country_code_picker/i18n/ko.json - - packages/country_code_picker/i18n/ky.json - - packages/country_code_picker/i18n/lt.json - - packages/country_code_picker/i18n/lv.json - - packages/country_code_picker/i18n/mk.json - - packages/country_code_picker/i18n/mn.json - - packages/country_code_picker/i18n/ms.json - - packages/country_code_picker/i18n/nb.json - - packages/country_code_picker/i18n/nl.json - - packages/country_code_picker/i18n/nn.json - - packages/country_code_picker/i18n/pl.json - - packages/country_code_picker/i18n/pt.json - - packages/country_code_picker/i18n/ro.json - - packages/country_code_picker/i18n/ru.json - - packages/country_code_picker/i18n/sk.json - - packages/country_code_picker/i18n/sl.json - - packages/country_code_picker/i18n/sr.json - - packages/country_code_picker/i18n/sv.json - - packages/country_code_picker/i18n/th.json - - packages/country_code_picker/i18n/tr.json - - packages/country_code_picker/i18n/uk.json - - packages/country_code_picker/i18n/uz.json - - packages/country_code_picker/i18n/zh.json + - packages/country_code_picker/src/i18n/af.json + - packages/country_code_picker/src/i18n/am.json + - packages/country_code_picker/src/i18n/ha.json + - packages/country_code_picker/src/i18n/ku.json + - packages/country_code_picker/src/i18n/ml.json + - packages/country_code_picker/src/i18n/no.json + - packages/country_code_picker/src/i18n/ps.json + - packages/country_code_picker/src/i18n/sd.json + - packages/country_code_picker/src/i18n/so.json + - packages/country_code_picker/src/i18n/sq.json + - packages/country_code_picker/src/i18n/ta.json + - packages/country_code_picker/src/i18n/tg.json + - packages/country_code_picker/src/i18n/tt.json + - packages/country_code_picker/src/i18n/ug.json + - packages/country_code_picker/src/i18n/ur.json + - packages/country_code_picker/src/i18n/vi.json + - packages/country_code_picker/src/i18n/ar.json + - packages/country_code_picker/src/i18n/az.json + - packages/country_code_picker/src/i18n/be.json + - packages/country_code_picker/src/i18n/bg.json + - packages/country_code_picker/src/i18n/bn.json + - packages/country_code_picker/src/i18n/bs.json + - packages/country_code_picker/src/i18n/ca.json + - packages/country_code_picker/src/i18n/cs.json + - packages/country_code_picker/src/i18n/da.json + - packages/country_code_picker/src/i18n/de.json + - packages/country_code_picker/src/i18n/el.json + - packages/country_code_picker/src/i18n/en.json + - packages/country_code_picker/src/i18n/es.json + - packages/country_code_picker/src/i18n/et.json + - packages/country_code_picker/src/i18n/fa.json + - packages/country_code_picker/src/i18n/fi.json + - packages/country_code_picker/src/i18n/fr.json + - packages/country_code_picker/src/i18n/gl.json + - packages/country_code_picker/src/i18n/el.json + - packages/country_code_picker/src/i18n/he.json + - packages/country_code_picker/src/i18n/hi.json + - packages/country_code_picker/src/i18n/hr.json + - packages/country_code_picker/src/i18n/hu.json + - packages/country_code_picker/src/i18n/hy.json + - packages/country_code_picker/src/i18n/id.json + - packages/country_code_picker/src/i18n/is.json + - packages/country_code_picker/src/i18n/it.json + - packages/country_code_picker/src/i18n/ja.json + - packages/country_code_picker/src/i18n/ka.json + - packages/country_code_picker/src/i18n/kk.json + - packages/country_code_picker/src/i18n/km.json + - packages/country_code_picker/src/i18n/ko.json + - packages/country_code_picker/src/i18n/ky.json + - packages/country_code_picker/src/i18n/lt.json + - packages/country_code_picker/src/i18n/lv.json + - packages/country_code_picker/src/i18n/mk.json + - packages/country_code_picker/src/i18n/mn.json + - packages/country_code_picker/src/i18n/ms.json + - packages/country_code_picker/src/i18n/nb.json + - packages/country_code_picker/src/i18n/nl.json + - packages/country_code_picker/src/i18n/nn.json + - packages/country_code_picker/src/i18n/pl.json + - packages/country_code_picker/src/i18n/pt.json + - packages/country_code_picker/src/i18n/ro.json + - packages/country_code_picker/src/i18n/ru.json + - packages/country_code_picker/src/i18n/sk.json + - packages/country_code_picker/src/i18n/sl.json + - packages/country_code_picker/src/i18n/sr.json + - packages/country_code_picker/src/i18n/sv.json + - packages/country_code_picker/src/i18n/th.json + - packages/country_code_picker/src/i18n/tr.json + - packages/country_code_picker/src/i18n/uk.json + - packages/country_code_picker/src/i18n/uz.json + - packages/country_code_picker/src/i18n/zh.json + +dev_dependencies: + flutter_lints: ^2.0.1 diff --git a/screenshots/screen1.png b/screenshots/screen1.png index ebb6a193..2b33cf10 100644 Binary files a/screenshots/screen1.png and b/screenshots/screen1.png differ diff --git a/screenshots/screen2.png b/screenshots/screen2.png index 9c02d84b..ea35c36b 100644 Binary files a/screenshots/screen2.png and b/screenshots/screen2.png differ