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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
}
defaultConfig {
minSdkVersion 16
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
lintOptions {
disable 'InvalidPackage'
Expand Down
10 changes: 5 additions & 5 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 {
Expand All @@ -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'
}
12 changes: 9 additions & 3 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_country_picker_example"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -28,8 +27,15 @@
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}

}
3 changes: 3 additions & 0 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item>
</style>
</resources>
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand Down
2 changes: 2 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 12 additions & 12 deletions lib/country.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
});

Expand Down Expand Up @@ -2296,25 +2296,25 @@ 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,
);
}

/// 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,
);
Expand Down
58 changes: 29 additions & 29 deletions lib/flutter_country_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export 'country.dart';

const _platform = const MethodChannel('biessek.rocks/flutter_country_picker');
Future<List<Country>> _fetchLocalizedCountryNames() async {
List<Country> renamed = new List();
Map result;
List<Country> renamed = [];
Map? result;
try {
var isoCodes = <String>[];
Country.ALL.forEach((Country country) {
Expand All @@ -22,7 +22,7 @@ Future<List<Country>> _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));
Expand All @@ -34,9 +34,9 @@ Future<List<Country>> _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,
Expand All @@ -49,35 +49,35 @@ class CountryPicker extends StatelessWidget {
this.currencyISOTextStyle,
}) : super(key: key);

final Country selectedCountry;
final Country? selectedCountry;
final ValueChanged<Country> onChanged;
final bool dense;
final bool showFlag;
final bool showDialingCode;
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 =
Country.findByIsoCode(Localizations.localeOf(context).countryCode);
}

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,
Expand All @@ -86,33 +86,33 @@ class CountryPicker extends StatelessWidget {
if (showFlag)
Container(
child: Image.asset(
displayCountry.asset,
displayCountry!.asset,
package: "flutter_country_picker",
height: 32.0,
fit: BoxFit.fitWidth,
)),
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,
Expand All @@ -122,7 +122,7 @@ class CountryPicker extends StatelessWidget {
],
),
onTap: () {
_selectCountry(context, displayCountry);
_selectCountry(context, displayCountry!);
},
);
}
Expand Down Expand Up @@ -153,7 +153,7 @@ class CountryPicker extends StatelessWidget {

Future<Null> _selectCountry(
BuildContext context, Country defaultCountry) async {
final Country picked = await showCountryPicker(
final Country? picked = await showCountryPicker(
context: context,
defaultCountry: defaultCountry,
);
Expand All @@ -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<Country> showCountryPicker({
BuildContext context,
Country defaultCountry,
Future<Country?> showCountryPicker({
required BuildContext context,
required Country defaultCountry,
}) async {
assert(Country.findByIsoCode(defaultCountry.isoCode) != null);

Expand All @@ -180,8 +180,8 @@ Future<Country> showCountryPicker({

class _CountryPickerDialog extends StatefulWidget {
const _CountryPickerDialog({
Key key,
Country defaultCountry,
Key? key,
Country? defaultCountry,
}) : super(key: key);

@override
Expand All @@ -190,8 +190,8 @@ class _CountryPickerDialog extends StatefulWidget {

class _CountryPickerDialogState extends State<_CountryPickerDialog> {
TextEditingController controller = new TextEditingController();
String filter;
List<Country> countries;
String? filter;
List<Country> countries=[];

@override
void initState() {
Expand Down Expand Up @@ -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}"),
Expand Down
7 changes: 3 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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 <alessandrobiessek@gmail.com>
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:
Expand Down