Skip to content

Commit d813a47

Browse files
feat: add missing focus to fields
1 parent 35b592b commit d813a47

8 files changed

+237
-216
lines changed

lib/src/fields/form_builder_checkbox_group.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class FormBuilderCheckboxGroup<T> extends FormBuilderFieldDecoration<List<T>> {
7171

7272
return InputDecorator(
7373
decoration: state.decoration,
74+
isFocused: state.effectiveFocusNode.hasFocus,
7475
child: GroupedCheckbox<T>(
76+
focusNode: state.effectiveFocusNode,
7577
orientation: orientation,
7678
value: state.value,
7779
options: options,

lib/src/fields/form_builder_choice_chips.dart

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -395,57 +395,60 @@ class FormBuilderChoiceChip<T> extends FormBuilderFieldDecoration<T> {
395395
}) : super(builder: (FormFieldState<T?> field) {
396396
final state = field as _FormBuilderChoiceChipState<T>;
397397

398-
return InputDecorator(
399-
decoration: state.decoration,
400-
isFocused: state.effectiveFocusNode.hasFocus,
401-
child: Wrap(
402-
direction: direction,
403-
alignment: alignment,
404-
crossAxisAlignment: crossAxisAlignment,
405-
runAlignment: runAlignment,
406-
runSpacing: runSpacing,
407-
spacing: spacing,
408-
textDirection: textDirection,
409-
verticalDirection: verticalDirection,
410-
children: <Widget>[
411-
for (FormBuilderChipOption<T> option in options)
412-
ChoiceChip(
413-
label: option,
414-
side: side,
415-
shape: shape,
416-
selected: field.value == option.value,
417-
onSelected: state.enabled
418-
? (selected) {
419-
final choice = selected ? option.value : null;
420-
state.didChange(choice);
421-
}
422-
: null,
423-
avatar: option.avatar,
424-
selectedColor: selectedColor,
425-
disabledColor: disabledColor,
426-
backgroundColor: backgroundColor,
427-
shadowColor: shadowColor,
428-
selectedShadowColor: selectedShadowColor,
429-
elevation: elevation,
430-
pressElevation: pressElevation,
431-
materialTapTargetSize: materialTapTargetSize,
432-
labelStyle: labelStyle,
433-
labelPadding: labelPadding,
434-
padding: padding,
435-
visualDensity: visualDensity,
436-
avatarBorder: avatarBorder,
437-
showCheckmark: showCheckmark,
438-
surfaceTintColor: surfaceTintColor,
439-
clipBehavior: clipBehavior,
440-
checkmarkColor: checkmarkColor,
441-
autofocus: autofocus,
442-
avatarBoxConstraints: avatarBoxConstraints,
443-
chipAnimationStyle: chipAnimationStyle,
444-
color: color,
445-
iconTheme: iconTheme,
446-
tooltip: tooltip,
447-
),
448-
],
398+
return Focus(
399+
focusNode: state.effectiveFocusNode,
400+
child: InputDecorator(
401+
decoration: state.decoration,
402+
isFocused: state.effectiveFocusNode.hasFocus,
403+
child: Wrap(
404+
direction: direction,
405+
alignment: alignment,
406+
crossAxisAlignment: crossAxisAlignment,
407+
runAlignment: runAlignment,
408+
runSpacing: runSpacing,
409+
spacing: spacing,
410+
textDirection: textDirection,
411+
verticalDirection: verticalDirection,
412+
children: <Widget>[
413+
for (FormBuilderChipOption<T> option in options)
414+
ChoiceChip(
415+
label: option,
416+
side: side,
417+
shape: shape,
418+
selected: field.value == option.value,
419+
onSelected: state.enabled
420+
? (selected) {
421+
final choice = selected ? option.value : null;
422+
state.didChange(choice);
423+
}
424+
: null,
425+
avatar: option.avatar,
426+
selectedColor: selectedColor,
427+
disabledColor: disabledColor,
428+
backgroundColor: backgroundColor,
429+
shadowColor: shadowColor,
430+
selectedShadowColor: selectedShadowColor,
431+
elevation: elevation,
432+
pressElevation: pressElevation,
433+
materialTapTargetSize: materialTapTargetSize,
434+
labelStyle: labelStyle,
435+
labelPadding: labelPadding,
436+
padding: padding,
437+
visualDensity: visualDensity,
438+
avatarBorder: avatarBorder,
439+
showCheckmark: showCheckmark,
440+
surfaceTintColor: surfaceTintColor,
441+
clipBehavior: clipBehavior,
442+
checkmarkColor: checkmarkColor,
443+
autofocus: autofocus,
444+
avatarBoxConstraints: avatarBoxConstraints,
445+
chipAnimationStyle: chipAnimationStyle,
446+
color: color,
447+
iconTheme: iconTheme,
448+
tooltip: tooltip,
449+
),
450+
],
451+
),
449452
),
450453
);
451454
});

lib/src/fields/form_builder_filter_chips.dart

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -82,55 +82,59 @@ class FormBuilderFilterChip<T> extends FormBuilderFieldDecoration<List<T>> {
8282
final state = field as _FormBuilderFilterChipState<T>;
8383
final fieldValue = field.value ?? [];
8484

85-
return InputDecorator(
86-
decoration: state.decoration,
87-
child: Wrap(
88-
direction: direction,
89-
alignment: alignment,
90-
crossAxisAlignment: crossAxisAlignment,
91-
runAlignment: runAlignment,
92-
runSpacing: runSpacing,
93-
spacing: spacing,
94-
textDirection: textDirection,
95-
verticalDirection: verticalDirection,
96-
children: <Widget>[
97-
for (FormBuilderChipOption<T> option in options)
98-
FilterChip(
99-
label: option,
100-
selected: fieldValue.contains(option.value),
101-
avatar: option.avatar,
102-
onSelected: state.enabled &&
103-
(null == maxChips ||
104-
fieldValue.length < maxChips ||
105-
fieldValue.contains(option.value))
106-
? (selected) {
107-
final currentValue = [...fieldValue];
108-
selected
109-
? currentValue.add(option.value)
110-
: currentValue.remove(option.value);
85+
return Focus(
86+
focusNode: state.effectiveFocusNode,
87+
child: InputDecorator(
88+
decoration: state.decoration,
89+
isFocused: state.effectiveFocusNode.hasFocus,
90+
child: Wrap(
91+
direction: direction,
92+
alignment: alignment,
93+
crossAxisAlignment: crossAxisAlignment,
94+
runAlignment: runAlignment,
95+
runSpacing: runSpacing,
96+
spacing: spacing,
97+
textDirection: textDirection,
98+
verticalDirection: verticalDirection,
99+
children: <Widget>[
100+
for (FormBuilderChipOption<T> option in options)
101+
FilterChip(
102+
label: option,
103+
selected: fieldValue.contains(option.value),
104+
avatar: option.avatar,
105+
onSelected: state.enabled &&
106+
(null == maxChips ||
107+
fieldValue.length < maxChips ||
108+
fieldValue.contains(option.value))
109+
? (selected) {
110+
final currentValue = [...fieldValue];
111+
selected
112+
? currentValue.add(option.value)
113+
: currentValue.remove(option.value);
111114

112-
field.didChange(currentValue);
113-
}
114-
: null,
115-
selectedColor: selectedColor,
116-
disabledColor: disabledColor,
117-
backgroundColor: backgroundColor,
118-
shadowColor: shadowColor,
119-
selectedShadowColor: selectedShadowColor,
120-
elevation: elevation,
121-
pressElevation: pressElevation,
122-
materialTapTargetSize: materialTapTargetSize,
123-
padding: padding,
124-
side: side,
125-
shape: shape,
126-
checkmarkColor: checkmarkColor,
127-
clipBehavior: clipBehavior,
128-
labelStyle: labelStyle,
129-
showCheckmark: showCheckmark,
130-
labelPadding: labelPadding,
131-
avatarBorder: avatarBorder,
132-
),
133-
],
115+
field.didChange(currentValue);
116+
}
117+
: null,
118+
selectedColor: selectedColor,
119+
disabledColor: disabledColor,
120+
backgroundColor: backgroundColor,
121+
shadowColor: shadowColor,
122+
selectedShadowColor: selectedShadowColor,
123+
elevation: elevation,
124+
pressElevation: pressElevation,
125+
materialTapTargetSize: materialTapTargetSize,
126+
padding: padding,
127+
side: side,
128+
shape: shape,
129+
checkmarkColor: checkmarkColor,
130+
clipBehavior: clipBehavior,
131+
labelStyle: labelStyle,
132+
showCheckmark: showCheckmark,
133+
labelPadding: labelPadding,
134+
avatarBorder: avatarBorder,
135+
),
136+
],
137+
),
134138
),
135139
);
136140
},

lib/src/fields/form_builder_radio_group.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class FormBuilderRadioGroup<T> extends FormBuilderFieldDecoration<T> {
6565

6666
return InputDecorator(
6767
decoration: state.decoration,
68+
isFocused: state.effectiveFocusNode.hasFocus,
6869
child: GroupedRadio<T>(
70+
focusNode: state.effectiveFocusNode,
6971
activeColor: activeColor,
7072
controlAffinity: controlAffinity,
7173
disabled: state.enabled

lib/src/fields/form_builder_range_slider.dart

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -204,53 +204,57 @@ class FormBuilderRangeSlider extends FormBuilderFieldDecoration<RangeValues> {
204204
);
205205
}
206206
}
207-
return InputDecorator(
208-
decoration: state.decoration,
209-
child: Container(
210-
padding: const EdgeInsets.only(top: 10.0),
211-
child: Column(
212-
crossAxisAlignment: CrossAxisAlignment.start,
213-
children: [
214-
RangeSlider(
215-
values: field.value!,
216-
min: min,
217-
max: max,
218-
divisions: divisions,
219-
activeColor: activeColor,
220-
inactiveColor: inactiveColor,
221-
onChangeEnd: onChangeEnd,
222-
onChangeStart: onChangeStart,
223-
labels: labels,
224-
semanticFormatterCallback: semanticFormatterCallback,
225-
onChanged: state.enabled
226-
? (values) {
227-
field.didChange(values);
228-
}
229-
: null,
230-
),
231-
Row(
232-
children: <Widget>[
233-
if (displayValues != DisplayValues.none &&
234-
displayValues != DisplayValues.current)
235-
minValueWidget
236-
?.call(effectiveNumberFormat.format(min)) ??
237-
Text(effectiveNumberFormat.format(min)),
238-
const Spacer(),
239-
if (displayValues != DisplayValues.none &&
240-
displayValues != DisplayValues.minMax)
241-
valueWidget?.call(
242-
'${effectiveNumberFormat.format(field.value!.start)} - ${effectiveNumberFormat.format(field.value!.end)}') ??
243-
Text(
244-
'${effectiveNumberFormat.format(field.value!.start)} - ${effectiveNumberFormat.format(field.value!.end)}'),
245-
const Spacer(),
246-
if (displayValues != DisplayValues.none &&
247-
displayValues != DisplayValues.current)
248-
maxValueWidget
249-
?.call(effectiveNumberFormat.format(max)) ??
250-
Text(effectiveNumberFormat.format(max)),
251-
],
252-
),
253-
],
207+
return Focus(
208+
focusNode: state.effectiveFocusNode,
209+
child: InputDecorator(
210+
decoration: state.decoration,
211+
isFocused: state.effectiveFocusNode.hasFocus,
212+
child: Container(
213+
padding: const EdgeInsets.only(top: 10.0),
214+
child: Column(
215+
crossAxisAlignment: CrossAxisAlignment.start,
216+
children: [
217+
RangeSlider(
218+
values: field.value!,
219+
min: min,
220+
max: max,
221+
divisions: divisions,
222+
activeColor: activeColor,
223+
inactiveColor: inactiveColor,
224+
onChangeEnd: onChangeEnd,
225+
onChangeStart: onChangeStart,
226+
labels: labels,
227+
semanticFormatterCallback: semanticFormatterCallback,
228+
onChanged: state.enabled
229+
? (values) {
230+
field.didChange(values);
231+
}
232+
: null,
233+
),
234+
Row(
235+
children: <Widget>[
236+
if (displayValues != DisplayValues.none &&
237+
displayValues != DisplayValues.current)
238+
minValueWidget
239+
?.call(effectiveNumberFormat.format(min)) ??
240+
Text(effectiveNumberFormat.format(min)),
241+
const Spacer(),
242+
if (displayValues != DisplayValues.none &&
243+
displayValues != DisplayValues.minMax)
244+
valueWidget?.call(
245+
'${effectiveNumberFormat.format(field.value!.start)} - ${effectiveNumberFormat.format(field.value!.end)}') ??
246+
Text(
247+
'${effectiveNumberFormat.format(field.value!.start)} - ${effectiveNumberFormat.format(field.value!.end)}'),
248+
const Spacer(),
249+
if (displayValues != DisplayValues.none &&
250+
displayValues != DisplayValues.current)
251+
maxValueWidget
252+
?.call(effectiveNumberFormat.format(max)) ??
253+
Text(effectiveNumberFormat.format(max)),
254+
],
255+
),
256+
],
257+
),
254258
),
255259
),
256260
);

lib/src/fields/form_builder_switch.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ class FormBuilderSwitch extends FormBuilderFieldDecoration<bool> {
122122

123123
return InputDecorator(
124124
decoration: state.decoration,
125+
isFocused: state.effectiveFocusNode.hasFocus,
125126
child: SwitchListTile(
127+
focusNode: state.effectiveFocusNode,
126128
dense: true,
127129
isThreeLine: false,
128130
contentPadding: contentPadding,

0 commit comments

Comments
 (0)