Skip to content

Commit ee2bdb2

Browse files
committed
Merge branch 'grundid/master'
# Conflicts: # packages/form_builder_extra_fields/test/form_builder_tester.dart
2 parents d54f824 + 58904cc commit ee2bdb2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

packages/flutter_form_builder/test/form_builder_filter_chips_test.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,45 @@ void main() {
3030
expect(formSave(), isTrue);
3131
expect(formValue(widgetName), equals(<num>[1, 3]));
3232
});
33+
testWidgets('FormBuilderCheckboxGroup -- didChange',
34+
(WidgetTester tester) async {
35+
const fieldName = 'cbg1';
36+
final testWidget = FormBuilderCheckboxGroup<int>(
37+
name: fieldName,
38+
options: const [
39+
FormBuilderFieldOption(key: ValueKey('1'), value: 1),
40+
FormBuilderFieldOption(key: ValueKey('2'), value: 2),
41+
FormBuilderFieldOption(key: ValueKey('3'), value: 3),
42+
],
43+
);
44+
await tester.pumpWidget(buildTestableFieldWidget(testWidget));
45+
46+
expect(formSave(), isTrue);
47+
expect(formValue(fieldName), isNull);
48+
formFieldDidChange(fieldName, [1, 3]);
49+
await tester.pumpAndSettle();
50+
expect(formSave(), isTrue);
51+
expect(formValue(fieldName), [1, 3]);
52+
53+
Checkbox checkbox1 = tester
54+
.element(find.byKey(const ValueKey('1')))
55+
.findAncestorWidgetOfExactType<Row>()!
56+
.children
57+
.first as Checkbox;
58+
Checkbox checkbox2 = tester
59+
.element(find.byKey(const ValueKey('2')))
60+
.findAncestorWidgetOfExactType<Row>()!
61+
.children
62+
.first as Checkbox;
63+
Checkbox checkbox3 = tester
64+
.element(find.byKey(const ValueKey('3')))
65+
.findAncestorWidgetOfExactType<Row>()!
66+
.children
67+
.first as Checkbox;
68+
69+
// checkboxes should represent the state of the didChange value
70+
expect(checkbox1.value, true);
71+
expect(checkbox2.value, false);
72+
expect(checkbox3.value, true);
73+
});
3374
}

packages/form_builder_extra_fields/test/form_builder_tester.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ Widget buildTestableFieldWidget(Widget widget) {
1515
}
1616

1717
bool formSave() => _formKey.currentState!.saveAndValidate();
18+
void formFieldDidChange(String fieldName, dynamic value) {
19+
_formKey.currentState!.fields[fieldName]!.didChange(value);
20+
}
21+
1822
dynamic formFieldValue(String name) => _formKey.currentState!.value[name];

0 commit comments

Comments
 (0)