Skip to content

Commit ae9d1bf

Browse files
committed
add country filter to country dropdown
1 parent 35bfecc commit ae9d1bf

3 files changed

Lines changed: 142 additions & 73 deletions

File tree

example/pubspec.lock

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,88 @@ packages:
55
dependency: transitive
66
description:
77
name: async
8-
url: "https://pub.dartlang.org"
8+
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
9+
url: "https://pub.dev"
910
source: hosted
10-
version: "2.9.0"
11+
version: "2.10.0"
1112
base58check:
1213
dependency: transitive
1314
description:
1415
name: base58check
15-
url: "https://pub.dartlang.org"
16+
sha256: "6c300dfc33e598d2fe26319e13f6243fea81eaf8204cb4c6b69ef20a625319a5"
17+
url: "https://pub.dev"
1618
source: hosted
1719
version: "2.0.0"
1820
bech32:
1921
dependency: transitive
2022
description:
2123
name: bech32
22-
url: "https://pub.dartlang.org"
24+
sha256: "156cbace936f7720c79a79d16a03efad343b1ef17106716e04b8b8e39f99f7f7"
25+
url: "https://pub.dev"
2326
source: hosted
2427
version: "0.2.2"
2528
boolean_selector:
2629
dependency: transitive
2730
description:
2831
name: boolean_selector
29-
url: "https://pub.dartlang.org"
32+
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
33+
url: "https://pub.dev"
3034
source: hosted
31-
version: "2.1.0"
35+
version: "2.1.1"
3236
characters:
3337
dependency: transitive
3438
description:
3539
name: characters
36-
url: "https://pub.dartlang.org"
40+
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
41+
url: "https://pub.dev"
3742
source: hosted
3843
version: "1.2.1"
3944
clock:
4045
dependency: transitive
4146
description:
4247
name: clock
43-
url: "https://pub.dartlang.org"
48+
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
49+
url: "https://pub.dev"
4450
source: hosted
4551
version: "1.1.1"
4652
collection:
4753
dependency: transitive
4854
description:
4955
name: collection
50-
url: "https://pub.dartlang.org"
56+
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
57+
url: "https://pub.dev"
5158
source: hosted
52-
version: "1.16.0"
59+
version: "1.17.0"
5360
convert:
5461
dependency: transitive
5562
description:
5663
name: convert
57-
url: "https://pub.dartlang.org"
64+
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
65+
url: "https://pub.dev"
5866
source: hosted
5967
version: "3.1.1"
6068
crypto:
6169
dependency: transitive
6270
description:
6371
name: crypto
64-
url: "https://pub.dartlang.org"
72+
sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67
73+
url: "https://pub.dev"
6574
source: hosted
6675
version: "3.0.2"
6776
cupertino_icons:
6877
dependency: "direct main"
6978
description:
7079
name: cupertino_icons
71-
url: "https://pub.dartlang.org"
80+
sha256: a937da4c006989739ceb4d10e3bd6cce64ca85d0fe287fc5b2b9f6ee757dcee6
81+
url: "https://pub.dev"
7282
source: hosted
7383
version: "0.1.3"
7484
fake_async:
7585
dependency: transitive
7686
description:
7787
name: fake_async
78-
url: "https://pub.dartlang.org"
88+
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
89+
url: "https://pub.dev"
7990
source: hosted
8091
version: "1.3.1"
8192
flutter:
@@ -95,32 +106,44 @@ packages:
95106
description: flutter
96107
source: sdk
97108
version: "0.0.0"
109+
js:
110+
dependency: transitive
111+
description:
112+
name: js
113+
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
114+
url: "https://pub.dev"
115+
source: hosted
116+
version: "0.6.5"
98117
matcher:
99118
dependency: transitive
100119
description:
101120
name: matcher
102-
url: "https://pub.dartlang.org"
121+
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
122+
url: "https://pub.dev"
103123
source: hosted
104-
version: "0.12.12"
124+
version: "0.12.13"
105125
material_color_utilities:
106126
dependency: transitive
107127
description:
108128
name: material_color_utilities
109-
url: "https://pub.dartlang.org"
129+
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
130+
url: "https://pub.dev"
110131
source: hosted
111-
version: "0.1.5"
132+
version: "0.2.0"
112133
meta:
113134
dependency: transitive
114135
description:
115136
name: meta
116-
url: "https://pub.dartlang.org"
137+
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
138+
url: "https://pub.dev"
117139
source: hosted
118140
version: "1.8.0"
119141
path:
120142
dependency: transitive
121143
description:
122144
name: path
123-
url: "https://pub.dartlang.org"
145+
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
146+
url: "https://pub.dev"
124147
source: hosted
125148
version: "1.8.2"
126149
sky_engine:
@@ -132,58 +155,66 @@ packages:
132155
dependency: transitive
133156
description:
134157
name: source_span
135-
url: "https://pub.dartlang.org"
158+
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
159+
url: "https://pub.dev"
136160
source: hosted
137-
version: "1.9.0"
161+
version: "1.9.1"
138162
stack_trace:
139163
dependency: transitive
140164
description:
141165
name: stack_trace
142-
url: "https://pub.dartlang.org"
166+
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
167+
url: "https://pub.dev"
143168
source: hosted
144-
version: "1.10.0"
169+
version: "1.11.0"
145170
stream_channel:
146171
dependency: transitive
147172
description:
148173
name: stream_channel
149-
url: "https://pub.dartlang.org"
174+
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
175+
url: "https://pub.dev"
150176
source: hosted
151-
version: "2.1.0"
177+
version: "2.1.1"
152178
string_scanner:
153179
dependency: transitive
154180
description:
155181
name: string_scanner
156-
url: "https://pub.dartlang.org"
182+
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
183+
url: "https://pub.dev"
157184
source: hosted
158-
version: "1.1.1"
185+
version: "1.2.0"
159186
term_glyph:
160187
dependency: transitive
161188
description:
162189
name: term_glyph
163-
url: "https://pub.dartlang.org"
190+
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
191+
url: "https://pub.dev"
164192
source: hosted
165193
version: "1.2.1"
166194
test_api:
167195
dependency: transitive
168196
description:
169197
name: test_api
170-
url: "https://pub.dartlang.org"
198+
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
199+
url: "https://pub.dev"
171200
source: hosted
172-
version: "0.4.12"
201+
version: "0.4.16"
173202
typed_data:
174203
dependency: transitive
175204
description:
176205
name: typed_data
177-
url: "https://pub.dartlang.org"
206+
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
207+
url: "https://pub.dev"
178208
source: hosted
179209
version: "1.3.1"
180210
vector_math:
181211
dependency: transitive
182212
description:
183213
name: vector_math
184-
url: "https://pub.dartlang.org"
214+
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
215+
url: "https://pub.dev"
185216
source: hosted
186-
version: "2.1.2"
217+
version: "2.1.4"
187218
sdks:
188219
dart: ">=2.18.0 <3.0.0"
189220
flutter: ">=2.0.0"

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)