Skip to content

Commit 70f761b

Browse files
committed
added filter to CountryDropdown
1 parent d14f35b commit 70f761b

10 files changed

Lines changed: 359 additions & 338 deletions

File tree

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
## [2.10.5]
2+
- CountryDropdown can now be filtered. If you need it to show only a
3+
predefined list of countries. Just pass "filter" parameter like this
4+
```child: CountryDropdown(
5+
printCountryName: true,
6+
initialPhoneCode: '7',
7+
filter: PhoneCodes.findCountryDatasByCountryCodes(
8+
countryIsoCodes: [
9+
'RU',
10+
'BR',
11+
'DE',
12+
],
13+
),
14+
onCountrySelected: (PhoneCountryData countryData) {
15+
setState(() {
16+
_initialCountryData = countryData;
17+
});
18+
},
19+
)
20+
```
121
## [2.10.4]
222
- Unfocuser now has isEnabled parameter so it can be easily disabled when it's
323
not necessage e.g. on the web

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ Row(
125125
)
126126
```
127127

128+
You can also filter the list of countries if you need
129+
130+
```dart
131+
CountryDropdown(
132+
printCountryName: true,
133+
initialPhoneCode: '7',
134+
filter: PhoneCodes.findCountryDatasByCountryCodes(
135+
countryIsoCodes: [
136+
'RU',
137+
'BR',
138+
'DE',
139+
],
140+
)
141+
```
142+
128143

129144
### Formatting a credit / debit card
130145

example/lib/pages/phone_format_page.dart

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class _PhoneFormatPageState extends State<PhoneFormatPage> {
1313
TextEditingController _russianPhoneController =
1414
TextEditingController(text: '9998887766');
1515
PhoneCountryData? _initialCountryData;
16+
PhoneCountryData? _initialCountryDataFiltered;
1617

1718
@override
1819
void dispose() {
@@ -121,10 +122,63 @@ class _PhoneFormatPageState extends State<PhoneFormatPage> {
121122
)
122123
],
123124
),
125+
SizedBox(height: 30.0),
126+
_getText(
127+
'The next input uses a predefined country code',
128+
),
129+
Row(
130+
children: [
131+
Expanded(
132+
flex: 3,
133+
child: CountryDropdown(
134+
printCountryName: true,
135+
initialPhoneCode: '7',
136+
filter: PhoneCodes.findCountryDatasByCountryCodes(
137+
countryIsoCodes: [
138+
'RU',
139+
'BR',
140+
'DE',
141+
],
142+
),
143+
onCountrySelected: (PhoneCountryData countryData) {
144+
setState(() {
145+
_initialCountryDataFiltered = countryData;
146+
});
147+
},
148+
),
149+
),
150+
SizedBox(width: 10.0),
151+
Expanded(
152+
flex: 5,
153+
child: TextFormField(
154+
key: ValueKey(
155+
_initialCountryDataFiltered ?? 'country'),
156+
decoration: InputDecoration(
157+
border: OutlineInputBorder(),
158+
hintText: _initialCountryDataFiltered
159+
?.phoneMaskWithoutCountryCode,
160+
hintStyle:
161+
TextStyle(color: Colors.black.withOpacity(.3)),
162+
errorStyle: TextStyle(
163+
color: Colors.red,
164+
),
165+
),
166+
keyboardType: TextInputType.phone,
167+
inputFormatters: [
168+
PhoneInputFormatter(
169+
allowEndlessPhone: true,
170+
defaultCountryCode:
171+
_initialCountryDataFiltered?.countryCode,
172+
)
173+
],
174+
),
175+
)
176+
],
177+
),
124178
_getText(
125-
_initialCountryData == null
179+
_initialCountryDataFiltered == null
126180
? 'A country is not detected'
127-
: 'The country is: ${_initialCountryData?.country}',
181+
: 'The country is: ${_initialCountryDataFiltered?.country}',
128182
),
129183
SizedBox(
130184
height: 10.0,

example/pubspec.lock

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Generated by pub
2+
# See https://dart.dev/tools/pub/glossary#lockfile
3+
packages:
4+
async:
5+
dependency: transitive
6+
description:
7+
name: async
8+
url: "https://pub.dartlang.org"
9+
source: hosted
10+
version: "2.9.0"
11+
base58check:
12+
dependency: transitive
13+
description:
14+
name: base58check
15+
url: "https://pub.dartlang.org"
16+
source: hosted
17+
version: "2.0.0"
18+
bech32:
19+
dependency: transitive
20+
description:
21+
name: bech32
22+
url: "https://pub.dartlang.org"
23+
source: hosted
24+
version: "0.2.2"
25+
boolean_selector:
26+
dependency: transitive
27+
description:
28+
name: boolean_selector
29+
url: "https://pub.dartlang.org"
30+
source: hosted
31+
version: "2.1.0"
32+
characters:
33+
dependency: transitive
34+
description:
35+
name: characters
36+
url: "https://pub.dartlang.org"
37+
source: hosted
38+
version: "1.2.1"
39+
clock:
40+
dependency: transitive
41+
description:
42+
name: clock
43+
url: "https://pub.dartlang.org"
44+
source: hosted
45+
version: "1.1.1"
46+
collection:
47+
dependency: transitive
48+
description:
49+
name: collection
50+
url: "https://pub.dartlang.org"
51+
source: hosted
52+
version: "1.16.0"
53+
convert:
54+
dependency: transitive
55+
description:
56+
name: convert
57+
url: "https://pub.dartlang.org"
58+
source: hosted
59+
version: "3.1.1"
60+
crypto:
61+
dependency: transitive
62+
description:
63+
name: crypto
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "3.0.2"
67+
cupertino_icons:
68+
dependency: "direct main"
69+
description:
70+
name: cupertino_icons
71+
url: "https://pub.dartlang.org"
72+
source: hosted
73+
version: "0.1.3"
74+
fake_async:
75+
dependency: transitive
76+
description:
77+
name: fake_async
78+
url: "https://pub.dartlang.org"
79+
source: hosted
80+
version: "1.3.1"
81+
flutter:
82+
dependency: "direct main"
83+
description: flutter
84+
source: sdk
85+
version: "0.0.0"
86+
flutter_multi_formatter:
87+
dependency: "direct main"
88+
description:
89+
path: ".."
90+
relative: true
91+
source: path
92+
version: "2.10.5"
93+
flutter_test:
94+
dependency: "direct dev"
95+
description: flutter
96+
source: sdk
97+
version: "0.0.0"
98+
matcher:
99+
dependency: transitive
100+
description:
101+
name: matcher
102+
url: "https://pub.dartlang.org"
103+
source: hosted
104+
version: "0.12.12"
105+
material_color_utilities:
106+
dependency: transitive
107+
description:
108+
name: material_color_utilities
109+
url: "https://pub.dartlang.org"
110+
source: hosted
111+
version: "0.1.5"
112+
meta:
113+
dependency: transitive
114+
description:
115+
name: meta
116+
url: "https://pub.dartlang.org"
117+
source: hosted
118+
version: "1.8.0"
119+
path:
120+
dependency: transitive
121+
description:
122+
name: path
123+
url: "https://pub.dartlang.org"
124+
source: hosted
125+
version: "1.8.2"
126+
sky_engine:
127+
dependency: transitive
128+
description: flutter
129+
source: sdk
130+
version: "0.0.99"
131+
source_span:
132+
dependency: transitive
133+
description:
134+
name: source_span
135+
url: "https://pub.dartlang.org"
136+
source: hosted
137+
version: "1.9.0"
138+
stack_trace:
139+
dependency: transitive
140+
description:
141+
name: stack_trace
142+
url: "https://pub.dartlang.org"
143+
source: hosted
144+
version: "1.10.0"
145+
stream_channel:
146+
dependency: transitive
147+
description:
148+
name: stream_channel
149+
url: "https://pub.dartlang.org"
150+
source: hosted
151+
version: "2.1.0"
152+
string_scanner:
153+
dependency: transitive
154+
description:
155+
name: string_scanner
156+
url: "https://pub.dartlang.org"
157+
source: hosted
158+
version: "1.1.1"
159+
term_glyph:
160+
dependency: transitive
161+
description:
162+
name: term_glyph
163+
url: "https://pub.dartlang.org"
164+
source: hosted
165+
version: "1.2.1"
166+
test_api:
167+
dependency: transitive
168+
description:
169+
name: test_api
170+
url: "https://pub.dartlang.org"
171+
source: hosted
172+
version: "0.4.12"
173+
typed_data:
174+
dependency: transitive
175+
description:
176+
name: typed_data
177+
url: "https://pub.dartlang.org"
178+
source: hosted
179+
version: "1.3.1"
180+
vector_math:
181+
dependency: transitive
182+
description:
183+
name: vector_math
184+
url: "https://pub.dartlang.org"
185+
source: hosted
186+
version: "2.1.2"
187+
sdks:
188+
dart: ">=2.18.0 <3.0.0"
189+
flutter: ">=2.0.0"

0 commit comments

Comments
 (0)