Skip to content

Commit 0649dcd

Browse files
test: add focus test to all fields
1 parent 6f6b567 commit 0649dcd

14 files changed

+690
-359
lines changed

lib/src/fields/form_builder_checkbox.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ class FormBuilderCheckbox extends FormBuilderFieldDecoration<bool> {
125125

126126
return InputDecorator(
127127
decoration: state.decoration,
128+
isFocused: state.effectiveFocusNode.hasFocus,
128129
child: CheckboxListTile(
129130
dense: true,
130131
isThreeLine: false,
132+
focusNode: state.effectiveFocusNode,
131133
title: title,
132134
subtitle: subtitle,
133135
value: tristate ? state.value : (state.value ?? false),
@@ -158,4 +160,26 @@ class FormBuilderCheckbox extends FormBuilderFieldDecoration<bool> {
158160
}
159161

160162
class _FormBuilderCheckboxState
161-
extends FormBuilderFieldDecorationState<FormBuilderCheckbox, bool> {}
163+
extends FormBuilderFieldDecorationState<FormBuilderCheckbox, bool> {
164+
void handleFocusChange() {
165+
setState(() {});
166+
}
167+
168+
@override
169+
void initState() {
170+
super.initState();
171+
effectiveFocusNode.addListener(handleFocusChange);
172+
}
173+
174+
@override
175+
void dispose() {
176+
effectiveFocusNode.removeListener(handleFocusChange);
177+
super.dispose();
178+
}
179+
180+
@override
181+
void didChange(bool? value) {
182+
focus();
183+
super.didChange(value);
184+
}
185+
}

lib/src/fields/form_builder_choice_chips.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class FormBuilderChoiceChip<T> extends FormBuilderFieldDecoration<T> {
397397

398398
return InputDecorator(
399399
decoration: state.decoration,
400+
isFocused: state.effectiveFocusNode.hasFocus,
400401
child: Wrap(
401402
direction: direction,
402403
alignment: alignment,
@@ -455,4 +456,27 @@ class FormBuilderChoiceChip<T> extends FormBuilderFieldDecoration<T> {
455456
}
456457

457458
class _FormBuilderChoiceChipState<T>
458-
extends FormBuilderFieldDecorationState<FormBuilderChoiceChip<T>, T> {}
459+
extends FormBuilderFieldDecorationState<FormBuilderChoiceChip<T>, T> {
460+
void handleFocusChange() {
461+
setState(() {});
462+
}
463+
464+
@override
465+
void initState() {
466+
super.initState();
467+
effectiveFocusNode.addListener(handleFocusChange);
468+
}
469+
470+
@override
471+
void dispose() {
472+
effectiveFocusNode.removeListener(handleFocusChange);
473+
super.dispose();
474+
}
475+
476+
@override
477+
void didChange(T? value) {
478+
focus();
479+
// effectiveFocusNode.requestFocus();
480+
super.didChange(value);
481+
}
482+
}

0 commit comments

Comments
 (0)