diff --git a/android/build.gradle b/android/build.gradle index ccf4760..9f8a1ff 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -32,7 +32,7 @@ android { } defaultConfig { minSdkVersion 16 - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } lintOptions { disable 'InvalidPackage' diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 1bd1e63..bb6421b 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 27 + compileSdkVersion 28 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -30,10 +30,10 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "rocks.biessek.fluttercountrypickerexample" minSdkVersion 16 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { @@ -52,6 +52,6 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.1' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 4d2c4b5..44b6544 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -13,7 +13,6 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> + android:name="io.flutter.embedding.android.SplashScreenDrawable" + android:resource="@drawable/launch_background" /> + + diff --git a/example/android/app/src/main/kotlin/rocks/biessek/fluttercountrypickerexample/MainActivity.kt b/example/android/app/src/main/kotlin/rocks/biessek/fluttercountrypickerexample/MainActivity.kt index 32d1aba..e2d0fa9 100644 --- a/example/android/app/src/main/kotlin/rocks/biessek/fluttercountrypickerexample/MainActivity.kt +++ b/example/android/app/src/main/kotlin/rocks/biessek/fluttercountrypickerexample/MainActivity.kt @@ -1,13 +1,7 @@ package rocks.biessek.fluttercountrypickerexample -import android.os.Bundle - -import io.flutter.app.FlutterActivity -import io.flutter.plugins.GeneratedPluginRegistrant +import io.flutter.embedding.android.FlutterActivity; class MainActivity(): FlutterActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - GeneratedPluginRegistrant.registerWith(this) - } + } diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml index 00fa441..723556d 100644 --- a/example/android/app/src/main/res/values/styles.xml +++ b/example/android/app/src/main/res/values/styles.xml @@ -5,4 +5,7 @@ Flutter draws its first frame --> @drawable/launch_background + diff --git a/example/android/build.gradle b/example/android/build.gradle index 10cfe1b..f05df98 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.3.21' + ext.kotlin_version = '1.3.50' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + classpath 'com.android.tools.build:gradle:3.5.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 8bd86f6..53ae0ae 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1 +1,3 @@ +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 77e79b8..63ab3ae 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d17260e..f692627 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,9 @@ name: flutter_country_picker_example description: Demonstrates how to use the flutter_country_picker plugin. +environment: + sdk: '>=2.10.0 <3.0.0' + dependencies: flutter: sdk: flutter diff --git a/lib/country.dart b/lib/country.dart index a7c8175..ce3b162 100644 --- a/lib/country.dart +++ b/lib/country.dart @@ -20,11 +20,11 @@ class Country { /// Instantiates a [Country] with the specified [asset], [dialingCode] and [isoCode] const Country({ - @required this.asset, - @required this.dialingCode, - @required this.isoCode, - @required this.currency, - @required this.currencyISO, + required this.asset, + required this.dialingCode, + required this.isoCode, + required this.currency, + required this.currencyISO, this.name = "", }); @@ -2296,7 +2296,7 @@ class Country { /// returns a country with the specified [isoCode] or ```null``` if /// none or more than 1 are found - static findByIsoCode(String isoCode) { + static findByIsoCode(String? isoCode) { return ALL.singleWhere( (item) => item.isoCode == isoCode, ); @@ -2304,17 +2304,17 @@ class Country { /// Creates a copy with modified values Country copyWith({ - String name, - String isoCode, - String dialingCode, - String currency, - String currencyISO, + String? name, + String? isoCode, + String? dialingCode, + String? currency, + String? currencyISO, }) { return Country( name: name ?? this.name, isoCode: isoCode ?? this.isoCode, dialingCode: dialingCode ?? this.dialingCode, - asset: asset ?? this.asset, + asset: asset, currency: currency ?? this.currency, currencyISO: currencyISO ?? this.currencyISO, ); diff --git a/lib/flutter_country_picker.dart b/lib/flutter_country_picker.dart index 493eb8a..72dc897 100644 --- a/lib/flutter_country_picker.dart +++ b/lib/flutter_country_picker.dart @@ -8,8 +8,8 @@ export 'country.dart'; const _platform = const MethodChannel('biessek.rocks/flutter_country_picker'); Future> _fetchLocalizedCountryNames() async { - List renamed = new List(); - Map result; + List renamed = []; + Map? result; try { var isoCodes = []; Country.ALL.forEach((Country country) { @@ -22,7 +22,7 @@ Future> _fetchLocalizedCountryNames() async { } for (var country in Country.ALL) { - renamed.add(country.copyWith(name: result[country.isoCode])); + renamed.add(country.copyWith(name: result![country.isoCode])); } renamed.sort( (Country a, Country b) => removeDiacritics(a.name).compareTo(b.name)); @@ -34,9 +34,9 @@ Future> _fetchLocalizedCountryNames() async { /// pre defined list, see [Country.ALL] class CountryPicker extends StatelessWidget { const CountryPicker({ - Key key, + Key? key, this.selectedCountry, - @required this.onChanged, + required this.onChanged, this.dense = false, this.showFlag = true, this.showDialingCode = false, @@ -49,7 +49,7 @@ class CountryPicker extends StatelessWidget { this.currencyISOTextStyle, }) : super(key: key); - final Country selectedCountry; + final Country? selectedCountry; final ValueChanged onChanged; final bool dense; final bool showFlag; @@ -57,15 +57,15 @@ class CountryPicker extends StatelessWidget { final bool showName; final bool showCurrency; final bool showCurrencyISO; - final TextStyle nameTextStyle; - final TextStyle dialingCodeTextStyle; - final TextStyle currencyTextStyle; - final TextStyle currencyISOTextStyle; + final TextStyle? nameTextStyle; + final TextStyle? dialingCodeTextStyle; + final TextStyle? currencyTextStyle; + final TextStyle? currencyISOTextStyle; @override Widget build(BuildContext context) { assert(debugCheckHasMaterial(context)); - Country displayCountry = selectedCountry; + Country? displayCountry = selectedCountry; if (displayCountry == null) { displayCountry = @@ -73,11 +73,11 @@ class CountryPicker extends StatelessWidget { } return dense - ? _renderDenseDisplay(context, displayCountry) + ? _renderDenseDisplay(context, displayCountry!) : _renderDefaultDisplay(context, displayCountry); } - _renderDefaultDisplay(BuildContext context, Country displayCountry) { + _renderDefaultDisplay(BuildContext context, Country? displayCountry) { return InkWell( child: Row( mainAxisSize: MainAxisSize.min, @@ -86,7 +86,7 @@ class CountryPicker extends StatelessWidget { if (showFlag) Container( child: Image.asset( - displayCountry.asset, + displayCountry!.asset, package: "flutter_country_picker", height: 32.0, fit: BoxFit.fitWidth, @@ -94,25 +94,25 @@ class CountryPicker extends StatelessWidget { if (showName) Container( child: Text( - " ${displayCountry.name}", + " ${displayCountry!.name}", style: nameTextStyle, )), if (showDialingCode) Container( child: Text( - " (+${displayCountry.dialingCode})", + " (+${displayCountry!.dialingCode})", style: dialingCodeTextStyle, )), if (showCurrency) Container( child: Text( - " ${displayCountry.currency}", + " ${displayCountry!.currency}", style: currencyTextStyle, )), if (showCurrencyISO) Container( child: Text( - " ${displayCountry.currencyISO}", + " ${displayCountry!.currencyISO}", style: currencyISOTextStyle, )), Icon(Icons.arrow_drop_down, @@ -122,7 +122,7 @@ class CountryPicker extends StatelessWidget { ], ), onTap: () { - _selectCountry(context, displayCountry); + _selectCountry(context, displayCountry!); }, ); } @@ -153,7 +153,7 @@ class CountryPicker extends StatelessWidget { Future _selectCountry( BuildContext context, Country defaultCountry) async { - final Country picked = await showCountryPicker( + final Country? picked = await showCountryPicker( context: context, defaultCountry: defaultCountry, ); @@ -164,9 +164,9 @@ class CountryPicker extends StatelessWidget { /// Display a [Dialog] with the country list to selection /// you can pass and [defaultCountry], see [Country.findByIsoCode] -Future showCountryPicker({ - BuildContext context, - Country defaultCountry, +Future showCountryPicker({ + required BuildContext context, + required Country defaultCountry, }) async { assert(Country.findByIsoCode(defaultCountry.isoCode) != null); @@ -180,8 +180,8 @@ Future showCountryPicker({ class _CountryPickerDialog extends StatefulWidget { const _CountryPickerDialog({ - Key key, - Country defaultCountry, + Key? key, + Country? defaultCountry, }) : super(key: key); @override @@ -190,8 +190,8 @@ class _CountryPickerDialog extends StatefulWidget { class _CountryPickerDialogState extends State<_CountryPickerDialog> { TextEditingController controller = new TextEditingController(); - String filter; - List countries; + String? filter; + List countries=[]; @override void initState() { @@ -252,8 +252,8 @@ class _CountryPickerDialogState extends State<_CountryPickerDialog> { filter == "" || country.name .toLowerCase() - .contains(filter.toLowerCase()) || - country.isoCode.contains(filter)) { + .contains(filter!.toLowerCase()) || + country.isoCode.contains(filter!)) { return InkWell( child: ListTile( trailing: Text("+ ${country.dialingCode}"), diff --git a/pubspec.yaml b/pubspec.yaml index a1e131c..0c6feb7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,17 +1,16 @@ name: flutter_country_picker description: A new flutter plugin project. -version: 0.1.6 +version: 1.0.0-nullsafety.1 author: Alessandro Biessek homepage: https://github.com/biessek/flutter_country_picker environment: - sdk: ">=2.3.0-dev.0.5 <3.0.0" -# sdk: ">=2.0.0-dev.28.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: sdk: flutter - diacritic: ^0.1.0 + diacritic: ^0.1.3 flutter: plugin: