@@ -121,10 +121,7 @@ class FormBuilderPhoneField extends FormBuilderFieldDecoration<String> {
121121 final Widget ? searchEmptyView;
122122
123123 /// Country picker button
124- final Widget Function (
125- Widget flag,
126- String countryCode,
127- )? countryPicker;
124+ final Widget Function (Widget flag, String countryCode)? countryPicker;
128125
129126 /// Creates field for international phone number input.
130127 FormBuilderPhoneField ({
@@ -194,104 +191,107 @@ class FormBuilderPhoneField extends FormBuilderFieldDecoration<String> {
194191 this .iconSelector,
195192 this .countryPicker,
196193 this .searchEmptyView,
197- }) : assert (initialValue == null || controller == null ),
198- super (
199- builder: (FormFieldState <String ?> field) {
200- final state = field as _FormBuilderPhoneFieldState ;
201-
202- return InputDecorator (
203- decoration: state.decoration,
204- child: Row (
205- children: < Widget > [
206- GestureDetector (
207- onTap: state.enabled
208- ? () {
209- state.focus ();
210- isCupertinoPicker
211- ? state._openCupertinoCountryPicker ()
212- : state._openCountryPickerDialog ();
213- }
214- : null ,
215- child: countryPicker != null
216- ? countryPicker (
217- CountryPickerUtils .getDefaultFlagImage (
218- state._selectedDialogCountry,
219- ),
220- '+${state ._selectedDialogCountry .phoneCode } ' ,
221- )
222- : Row (
223- children: < Widget > [
224- iconSelector ?? const Icon (Icons .arrow_drop_down),
225- const SizedBox (width: 10 ),
226- CountryPickerUtils .getDefaultFlagImage (
227- state._selectedDialogCountry,
228- ),
229- const SizedBox (width: 10 ),
230- Text (
231- '+${state ._selectedDialogCountry .phoneCode } ' ,
232- style: Theme .of (state.context)
233- .textTheme
234- .titleMedium!
235- .merge (style),
236- ),
237- ],
238- ),
239- ),
240- Expanded (
241- child: TextField (
242- enabled: state.enabled,
243- style: style,
244- focusNode: state.effectiveFocusNode,
245- decoration: InputDecoration (
246- border: InputBorder .none,
247- enabledBorder: InputBorder .none,
248- errorBorder: InputBorder .none,
249- hintText: decoration.hintText,
250- hintStyle: decoration.hintStyle,
251- filled: false ),
252- onChanged: (value) {
253- // Use setValue instead didChange to avoid parseNumber
254- state.setValue (value);
255- },
256- maxLines: 1 ,
257- keyboardType: keyboardType,
258- obscureText: obscureText,
259- onEditingComplete: onEditingComplete,
260- controller: state._effectiveController,
261- autocorrect: autocorrect,
262- autofocus: autofocus,
263- buildCounter: buildCounter,
264- cursorColor: cursorColor,
265- cursorRadius: cursorRadius,
266- cursorWidth: cursorWidth,
267- enableInteractiveSelection: enableInteractiveSelection,
268- maxLength: maxLength,
269- inputFormatters: inputFormatters,
270- keyboardAppearance: keyboardAppearance,
271- maxLengthEnforcement: maxLengthEnforcement,
272- scrollPadding: scrollPadding,
273- textAlign: textAlign,
274- textCapitalization: textCapitalization,
275- textDirection: textDirection,
276- textInputAction: textInputAction,
277- strutStyle: strutStyle,
278- //readOnly: state.readOnly, -- Does this need to be exposed?
279- expands: expands,
280- minLines: minLines,
281- showCursor: showCursor,
282- onTap: onTap,
283- textAlignVertical: textAlignVertical,
284- ),
285- ),
286- ],
287- ),
288- );
289- },
290- );
194+ }) : assert (initialValue == null || controller == null ),
195+ super (
196+ builder: (FormFieldState <String ?> field) {
197+ final state = field as _FormBuilderPhoneFieldState ;
198+
199+ return InputDecorator (
200+ decoration: state.decoration,
201+ child: Row (
202+ children: < Widget > [
203+ GestureDetector (
204+ onTap:
205+ state.enabled
206+ ? () {
207+ state.focus ();
208+ isCupertinoPicker
209+ ? state._openCupertinoCountryPicker ()
210+ : state._openCountryPickerDialog ();
211+ }
212+ : null ,
213+ child:
214+ countryPicker != null
215+ ? countryPicker (
216+ CountryPickerUtils .getDefaultFlagImage (
217+ state._selectedDialogCountry,
218+ ),
219+ '+${state ._selectedDialogCountry .phoneCode } ' ,
220+ )
221+ : Row (
222+ children: < Widget > [
223+ iconSelector ??
224+ const Icon (Icons .arrow_drop_down),
225+ const SizedBox (width: 10 ),
226+ CountryPickerUtils .getDefaultFlagImage (
227+ state._selectedDialogCountry,
228+ ),
229+ const SizedBox (width: 10 ),
230+ Text (
231+ '+${state ._selectedDialogCountry .phoneCode } ' ,
232+ style: Theme .of (
233+ state.context,
234+ ).textTheme.titleMedium! .merge (style),
235+ ),
236+ ],
237+ ),
238+ ),
239+ Expanded (
240+ child: TextField (
241+ enabled: state.enabled,
242+ style: style,
243+ focusNode: state.effectiveFocusNode,
244+ decoration: InputDecoration (
245+ border: InputBorder .none,
246+ enabledBorder: InputBorder .none,
247+ errorBorder: InputBorder .none,
248+ hintText: decoration.hintText,
249+ hintStyle: decoration.hintStyle,
250+ filled: false ,
251+ ),
252+ onChanged: (value) {
253+ // Use setValue instead didChange to avoid parseNumber
254+ state.setValue (value);
255+ },
256+ maxLines: 1 ,
257+ keyboardType: keyboardType,
258+ obscureText: obscureText,
259+ onEditingComplete: onEditingComplete,
260+ controller: state._effectiveController,
261+ autocorrect: autocorrect,
262+ autofocus: autofocus,
263+ buildCounter: buildCounter,
264+ cursorColor: cursorColor,
265+ cursorRadius: cursorRadius,
266+ cursorWidth: cursorWidth,
267+ enableInteractiveSelection: enableInteractiveSelection,
268+ maxLength: maxLength,
269+ inputFormatters: inputFormatters,
270+ keyboardAppearance: keyboardAppearance,
271+ maxLengthEnforcement: maxLengthEnforcement,
272+ scrollPadding: scrollPadding,
273+ textAlign: textAlign,
274+ textCapitalization: textCapitalization,
275+ textDirection: textDirection,
276+ textInputAction: textInputAction,
277+ strutStyle: strutStyle,
278+ //readOnly: state.readOnly, -- Does this need to be exposed?
279+ expands: expands,
280+ minLines: minLines,
281+ showCursor: showCursor,
282+ onTap: onTap,
283+ textAlignVertical: textAlignVertical,
284+ ),
285+ ),
286+ ],
287+ ),
288+ );
289+ },
290+ );
291291
292292 @override
293293 FormBuilderFieldDecorationState <FormBuilderPhoneField , String >
294- createState () => _FormBuilderPhoneFieldState ();
294+ createState () => _FormBuilderPhoneFieldState ();
295295}
296296
297297abstract class FormBuilderPhoneFieldState {
@@ -319,7 +319,8 @@ class _FormBuilderPhoneFieldState
319319 super .initState ();
320320 _effectiveController = widget.controller ?? TextEditingController ();
321321 _selectedDialogCountry = CountryPickerUtils .getCountryByIsoCode (
322- widget.defaultSelectedCountryIsoCode);
322+ widget.defaultSelectedCountryIsoCode,
323+ );
323324 _parsePhone ();
324325 }
325326
@@ -336,7 +337,8 @@ class _FormBuilderPhoneFieldState
336337 super .reset ();
337338 _effectiveController = widget.controller ?? TextEditingController ();
338339 _selectedDialogCountry = CountryPickerUtils .getCountryByIsoCode (
339- widget.defaultSelectedCountryIsoCode);
340+ widget.defaultSelectedCountryIsoCode,
341+ );
340342 _parsePhone ();
341343 }
342344
@@ -346,8 +348,9 @@ class _FormBuilderPhoneFieldState
346348 try {
347349 final parseResult = PhoneNumber .parse (phone);
348350 setState (() {
349- _selectedDialogCountry =
350- CountryPickerUtils .getCountryByIsoCode (parseResult.countryCode);
351+ _selectedDialogCountry = CountryPickerUtils .getCountryByIsoCode (
352+ parseResult.countryCode,
353+ );
351354 });
352355 _effectiveController.text = parseResult.nsn;
353356 } catch (error) {
@@ -376,19 +379,20 @@ class _FormBuilderPhoneFieldState
376379 setState (() => _selectedDialogCountry = country);
377380 didChange (fullNumber);
378381 },
379- itemFilter: widget.countryFilterByIsoCode != null
380- ? (c) => widget.countryFilterByIsoCode! .contains (c.isoCode)
381- : null ,
382- priorityList: widget.priorityListByIsoCode != null
383- ? List .generate (
384- widget.priorityListByIsoCode! .length,
385- (index) {
382+ itemFilter:
383+ widget.countryFilterByIsoCode != null
384+ ? (c) => widget.countryFilterByIsoCode! .contains (c.isoCode)
385+ : null ,
386+ priorityList:
387+ widget.priorityListByIsoCode != null
388+ ? List .generate (widget.priorityListByIsoCode! .length, (
389+ index,
390+ ) {
386391 return CountryPickerUtils .getCountryByIsoCode (
387392 widget.priorityListByIsoCode! [index],
388393 );
389- },
390- )
391- : null ,
394+ })
395+ : null ,
392396 offAxisFraction: widget.offAxisFraction,
393397 backgroundColor: widget.backgroundColor,
394398 diameterRatio: widget.diameterRatio,
@@ -420,11 +424,13 @@ class _FormBuilderPhoneFieldState
420424 titlePadding: widget.titlePadding ?? const EdgeInsets .all (8.0 ),
421425 searchCursorColor:
422426 widget.cursorColor ?? Theme .of (context).primaryColor,
423- searchInputDecoration:
424- InputDecoration (hintText: widget.searchText ?? 'Search...' ),
427+ searchInputDecoration: InputDecoration (
428+ hintText: widget.searchText ?? 'Search...' ,
429+ ),
425430 isSearchable: widget.isSearchable ?? true ,
426431 searchEmptyView: widget.searchEmptyView,
427- title: widget.dialogTitle ??
432+ title:
433+ widget.dialogTitle ??
428434 Text (
429435 'Select Your Phone Code' ,
430436 style: widget.dialogTextStyle ?? widget.style,
@@ -433,18 +439,20 @@ class _FormBuilderPhoneFieldState
433439 setState (() => _selectedDialogCountry = country);
434440 didChange (fullNumber);
435441 },
436- itemFilter: widget.countryFilterByIsoCode != null
437- ? (c) => widget.countryFilterByIsoCode! .contains (c.isoCode)
438- : null ,
439- priorityList: widget.priorityListByIsoCode != null
440- ? List .generate (
441- widget.priorityListByIsoCode! .length,
442- (index) {
442+ itemFilter:
443+ widget.countryFilterByIsoCode != null
444+ ? (c) => widget.countryFilterByIsoCode! .contains (c.isoCode)
445+ : null ,
446+ priorityList:
447+ widget.priorityListByIsoCode != null
448+ ? List .generate (widget.priorityListByIsoCode! .length, (
449+ index,
450+ ) {
443451 return CountryPickerUtils .getCountryByIsoCode (
444- widget.priorityListByIsoCode! [index]);
445- },
446- )
447- : null ,
452+ widget.priorityListByIsoCode! [index],
453+ );
454+ } )
455+ : null ,
448456 itemBuilder: _buildDialogItem,
449457 sortComparator: widget.sortComparator,
450458 ),
0 commit comments