Skip to content

Commit a4e07f2

Browse files
author
Tez
committed
customizable country picker added + searchEmptyView
1 parent 9e17e9a commit a4e07f2

File tree

5 files changed

+108
-48
lines changed

5 files changed

+108
-48
lines changed

example/ios/Podfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Uncomment this line to define a global platform for your project
2+
# platform :ios, '11.0'
3+
4+
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5+
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6+
7+
project 'Runner', {
8+
'Debug' => :debug,
9+
'Profile' => :release,
10+
'Release' => :release,
11+
}
12+
13+
def flutter_root
14+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15+
unless File.exist?(generated_xcode_build_settings_path)
16+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17+
end
18+
19+
File.foreach(generated_xcode_build_settings_path) do |line|
20+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
21+
return matches[1].strip if matches
22+
end
23+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24+
end
25+
26+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27+
28+
flutter_ios_podfile_setup
29+
30+
target 'Runner' do
31+
use_frameworks!
32+
use_modular_headers!
33+
34+
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35+
end
36+
37+
post_install do |installer|
38+
installer.pods_project.targets.each do |target|
39+
flutter_additional_ios_build_settings(target)
40+
end
41+
end

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MyApp extends StatelessWidget {
1717
title: 'Flutter Demo',
1818
// Locale config required by form_builder_validators
1919
// https://github.com/danvick/flutter_form_builder/blob/master/packages/form_builder_validators/example/lib/main.dart
20-
supportedLocales: [...FormBuilderLocalizations.delegate.supportedLocales],
20+
supportedLocales: const [...FormBuilderLocalizations.supportedLocales],
2121
localizationsDelegates: const [
2222
GlobalMaterialLocalizations.delegate,
2323
GlobalWidgetsLocalizations.delegate,

example/pubspec.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ packages:
2121
dependency: transitive
2222
description:
2323
name: characters
24-
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
24+
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
2525
url: "https://pub.dev"
2626
source: hosted
27-
version: "1.3.0"
27+
version: "1.2.1"
2828
clock:
2929
dependency: transitive
3030
description:
@@ -37,10 +37,10 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: collection
40-
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
40+
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "1.17.1"
43+
version: "1.17.0"
4444
country_pickers:
4545
dependency: transitive
4646
description:
@@ -115,10 +115,10 @@ packages:
115115
dependency: transitive
116116
description:
117117
name: js
118-
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
118+
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
119119
url: "https://pub.dev"
120120
source: hosted
121-
version: "0.6.7"
121+
version: "0.6.5"
122122
lints:
123123
dependency: transitive
124124
description:
@@ -131,10 +131,10 @@ packages:
131131
dependency: transitive
132132
description:
133133
name: matcher
134-
sha256: c94db23593b89766cda57aab9ac311e3616cf87c6fa4e9749df032f66f30dcb8
134+
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
135135
url: "https://pub.dev"
136136
source: hosted
137-
version: "0.12.14"
137+
version: "0.12.13"
138138
material_color_utilities:
139139
dependency: transitive
140140
description:
@@ -147,18 +147,18 @@ packages:
147147
dependency: transitive
148148
description:
149149
name: meta
150-
sha256: "12307e7f0605ce3da64cf0db90e5fcab0869f3ca03f76be6bb2991ce0a55e82b"
150+
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
151151
url: "https://pub.dev"
152152
source: hosted
153-
version: "1.9.0"
153+
version: "1.8.0"
154154
path:
155155
dependency: transitive
156156
description:
157157
name: path
158-
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
158+
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
159159
url: "https://pub.dev"
160160
source: hosted
161-
version: "1.8.3"
161+
version: "1.8.2"
162162
phone_number:
163163
dependency: transitive
164164
description:
@@ -216,10 +216,10 @@ packages:
216216
dependency: transitive
217217
description:
218218
name: test_api
219-
sha256: "6182294da5abf431177fccc1ee02401f6df30f766bc6130a0852c6b6d7ee6b2d"
219+
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
220220
url: "https://pub.dev"
221221
source: hosted
222-
version: "0.4.18"
222+
version: "0.4.16"
223223
vector_math:
224224
dependency: transitive
225225
description:

lib/src/form_builder_phone_field.dart

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ class FormBuilderPhoneField extends FormBuilderField<String> {
117117
/// By default this widget is `const Icon(Icons.arrow_drop_down)`
118118
final Widget? iconSelector;
119119

120+
/// View to display when search found no result
121+
final Widget? searchEmptyView;
122+
123+
/// Country picker button
124+
final Widget Function(
125+
Widget flag,
126+
String countryCode,
127+
)? countryPicker;
128+
120129
/// Creates field for international phone number input.
121130
FormBuilderPhoneField({
122131
Key? key,
@@ -184,6 +193,8 @@ class FormBuilderPhoneField extends FormBuilderField<String> {
184193
this.priorityList,
185194
this.itemBuilder,
186195
this.iconSelector,
196+
this.countryPicker,
197+
this.searchEmptyView,
187198
}) : assert(initialValue == null || controller == null),
188199
super(
189200
key: key,
@@ -214,23 +225,30 @@ class FormBuilderPhoneField extends FormBuilderField<String> {
214225
: state._openCountryPickerDialog();
215226
}
216227
: null,
217-
child: Row(
218-
children: <Widget>[
219-
iconSelector ?? const Icon(Icons.arrow_drop_down),
220-
const SizedBox(width: 10),
221-
CountryPickerUtils.getDefaultFlagImage(
222-
state._selectedDialogCountry,
223-
),
224-
const SizedBox(width: 10),
225-
Text(
226-
'+${state._selectedDialogCountry.phoneCode} ',
227-
style: Theme.of(state.context)
228-
.textTheme
229-
.subtitle1!
230-
.merge(style),
231-
),
232-
],
233-
),
228+
child: countryPicker != null
229+
? countryPicker(
230+
CountryPickerUtils.getDefaultFlagImage(
231+
state._selectedDialogCountry,
232+
),
233+
'+${state._selectedDialogCountry.phoneCode} ',
234+
)
235+
: Row(
236+
children: <Widget>[
237+
iconSelector ?? const Icon(Icons.arrow_drop_down),
238+
const SizedBox(width: 10),
239+
CountryPickerUtils.getDefaultFlagImage(
240+
state._selectedDialogCountry,
241+
),
242+
const SizedBox(width: 10),
243+
Text(
244+
'+${state._selectedDialogCountry.phoneCode} ',
245+
style: Theme.of(state.context)
246+
.textTheme
247+
.titleMedium!
248+
.merge(style),
249+
),
250+
],
251+
),
234252
),
235253
Expanded(
236254
child: TextField(
@@ -408,6 +426,7 @@ class _FormBuilderPhoneFieldState
408426
searchInputDecoration:
409427
InputDecoration(hintText: widget.searchText ?? 'Search...'),
410428
isSearchable: widget.isSearchable ?? true,
429+
searchEmptyView: widget.searchEmptyView,
411430
title: widget.dialogTitle ??
412431
Text(
413432
'Select Your Phone Code',

pubspec.lock

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ packages:
2121
dependency: transitive
2222
description:
2323
name: characters
24-
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
24+
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
2525
url: "https://pub.dev"
2626
source: hosted
27-
version: "1.3.0"
27+
version: "1.2.1"
2828
clock:
2929
dependency: transitive
3030
description:
@@ -37,10 +37,10 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: collection
40-
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
40+
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "1.17.1"
43+
version: "1.17.0"
4444
country_pickers:
4545
dependency: "direct main"
4646
description:
@@ -95,26 +95,26 @@ packages:
9595
dependency: transitive
9696
description:
9797
name: js
98-
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
98+
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
9999
url: "https://pub.dev"
100100
source: hosted
101-
version: "0.6.7"
101+
version: "0.6.5"
102102
lints:
103103
dependency: transitive
104104
description:
105105
name: lints
106-
sha256: "5cfd6509652ff5e7fe149b6df4859e687fca9048437857cb2e65c8d780f396e3"
106+
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
107107
url: "https://pub.dev"
108108
source: hosted
109-
version: "2.0.0"
109+
version: "2.0.1"
110110
matcher:
111111
dependency: transitive
112112
description:
113113
name: matcher
114-
sha256: c94db23593b89766cda57aab9ac311e3616cf87c6fa4e9749df032f66f30dcb8
114+
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
115115
url: "https://pub.dev"
116116
source: hosted
117-
version: "0.12.14"
117+
version: "0.12.13"
118118
material_color_utilities:
119119
dependency: transitive
120120
description:
@@ -127,18 +127,18 @@ packages:
127127
dependency: transitive
128128
description:
129129
name: meta
130-
sha256: "12307e7f0605ce3da64cf0db90e5fcab0869f3ca03f76be6bb2991ce0a55e82b"
130+
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
131131
url: "https://pub.dev"
132132
source: hosted
133-
version: "1.9.0"
133+
version: "1.8.0"
134134
path:
135135
dependency: transitive
136136
description:
137137
name: path
138-
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
138+
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
139139
url: "https://pub.dev"
140140
source: hosted
141-
version: "1.8.3"
141+
version: "1.8.2"
142142
phone_number:
143143
dependency: "direct main"
144144
description:
@@ -196,10 +196,10 @@ packages:
196196
dependency: transitive
197197
description:
198198
name: test_api
199-
sha256: "6182294da5abf431177fccc1ee02401f6df30f766bc6130a0852c6b6d7ee6b2d"
199+
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
200200
url: "https://pub.dev"
201201
source: hosted
202-
version: "0.4.18"
202+
version: "0.4.16"
203203
vector_math:
204204
dependency: transitive
205205
description:

0 commit comments

Comments
 (0)