Skip to content

Commit d14f35b

Browse files
authored
Merge pull request #126 from payam-zahedi/feat/country-filter
add country filters to country drop down
2 parents 35bfecc + 939e4cd commit d14f35b

7 files changed

Lines changed: 82 additions & 233 deletions

File tree

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 28
29+
compileSdkVersion 32
3030

3131
sourceSets {
3232
main.java.srcDirs += 'src/main/kotlin'

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
additional functionality it is fine to subclass or reimplement
77
FlutterApplication and put your custom class here. -->
88
<application
9-
android:name="io.flutter.app.FlutterApplication"
9+
android:name="${applicationName}"
1010
android:label="example"
1111
android:icon="@mipmap/ic_launcher">
1212
<activity

example/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.50'
2+
ext.kotlin_version = '1.6.10'
33
repositories {
44
google()
55
jcenter()
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.5.0'
9+
classpath 'com.android.tools.build:gradle:7.2.0'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

example/pubspec.lock

Lines changed: 0 additions & 189 deletions
This file was deleted.

lib/widgets/country_dropdown.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class CountryDropdown extends StatefulWidget {
1010
final CountryItemBuilder? listItemBuilder;
1111
final bool printCountryName;
1212
final String? initialPhoneCode;
13+
final List<PhoneCountryData>? countryItems;
1314
final ValueChanged<PhoneCountryData> onCountrySelected;
1415

1516
final int elevation;
@@ -44,6 +45,7 @@ class CountryDropdown extends StatefulWidget {
4445
this.listItemBuilder,
4546
this.printCountryName = false,
4647
this.initialPhoneCode,
48+
this.countryItems,
4749
required this.onCountrySelected,
4850
this.elevation = 8,
4951
this.style,
@@ -82,12 +84,18 @@ class _CountryDropdownState extends State<CountryDropdown> {
8284
}
8385

8486
PhoneCountryData get _initialValue {
87+
final items = _countryItems;
88+
8589
if (widget.initialPhoneCode != null) {
86-
return PhoneCodes.getAllCountryDatas().firstWhereOrNull((c) =>
87-
c.phoneCode == widget.initialPhoneCode) ??
88-
PhoneCodes.getAllCountryDatas().first;
90+
return items.firstWhereOrNull(
91+
(c) => c.phoneCode == widget.initialPhoneCode) ??
92+
items.first;
8993
}
90-
return PhoneCodes.getAllCountryDatas().first;
94+
return items.first;
95+
}
96+
97+
List<PhoneCountryData> get _countryItems {
98+
return widget.countryItems ?? PhoneCodes.getAllCountryDatas();
9199
}
92100

93101
Widget _buildSelectedLabel(
@@ -177,7 +185,7 @@ class _CountryDropdownState extends State<CountryDropdown> {
177185
elevation: widget.elevation,
178186
itemHeight: widget.itemHeight,
179187
selectedItemBuilder: (c) {
180-
return PhoneCodes.getAllCountryDatas()
188+
return _countryItems
181189
.map(
182190
(e) => DropdownMenuItem<PhoneCountryData>(
183191
child: _buildSelectedLabel(e),
@@ -186,7 +194,7 @@ class _CountryDropdownState extends State<CountryDropdown> {
186194
)
187195
.toList();
188196
},
189-
items: PhoneCodes.getAllCountryDatas()
197+
items: _countryItems
190198
.map(
191199
(e) => DropdownMenuItem<PhoneCountryData>(
192200
child: _buildListLabel(e),

0 commit comments

Comments
 (0)