Skip to content

Commit 483f02f

Browse files
Merge pull request #1489 from flutter-form-builder-ecosystem/bugfix/#1365-avoid-ovewrite-field-children
test: #1365 Add test to similar fields
2 parents fffb27d + 604fbb0 commit 483f02f

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

example/lib/minimal_code_example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class _ExamplePageState extends State<_ExamplePage> {
4343
child: FormBuilder(
4444
key: _formKey,
4545
child: Column(
46+
spacing: 16,
4647
children: [
4748
FormBuilderFilterChips<String>(
4849
decoration: const InputDecoration(
@@ -77,7 +78,6 @@ class _ExamplePageState extends State<_ExamplePage> {
7778
FormBuilderValidators.maxLength(3),
7879
]),
7980
),
80-
const SizedBox(height: 10),
8181
ElevatedButton(
8282
onPressed: () {
8383
_formKey.currentState?.saveAndValidate();

example/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ packages:
55
dependency: transitive
66
description:
77
name: async
8-
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
8+
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "2.12.0"
11+
version: "2.13.0"
1212
boolean_selector:
1313
dependency: transitive
1414
description:

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ packages:
55
dependency: transitive
66
description:
77
name: async
8-
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
8+
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "2.12.0"
11+
version: "2.13.0"
1212
boolean_selector:
1313
dependency: transitive
1414
description:

test/src/form_builder_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,61 @@ void main() {
621621
expect(formKey.currentState?.errors, equals({}));
622622
});
623623
});
624+
625+
group('multiple fields interaction -', () {
626+
testWidgets('Should update form builder fields when has similar fields', (
627+
tester,
628+
) async {
629+
// Arrange
630+
const firstDropdownName = '1_dropdown';
631+
const secondDropdownName = '2_dropdown';
632+
final firstDropdown = FormBuilderDropdown<int>(
633+
name: firstDropdownName,
634+
items: const [
635+
DropdownMenuItem(value: 1, child: Text('1')),
636+
DropdownMenuItem(value: 2, child: Text('2')),
637+
DropdownMenuItem(value: 3, child: Text('3')),
638+
],
639+
);
640+
final secondDropdown = FormBuilderDropdown(
641+
name: secondDropdownName,
642+
items: const [
643+
DropdownMenuItem(value: 1, child: Text('1')),
644+
DropdownMenuItem(value: 2, child: Text('2')),
645+
DropdownMenuItem(value: 3, child: Text('3')),
646+
],
647+
);
648+
await tester.pumpWidget(
649+
buildTestableFieldWidget(
650+
Column(children: [firstDropdown, secondDropdown]),
651+
),
652+
);
653+
654+
// Act
655+
final firstDropdownFinder = find.byWidget(firstDropdown);
656+
await tester.tap(firstDropdownFinder);
657+
await tester.pumpAndSettle();
658+
await tester.tap(find.text('1').last);
659+
await tester.pumpAndSettle();
660+
661+
// Assert
662+
expect(formInstantValue(firstDropdownName), 1);
663+
expect(formInstantValue(secondDropdownName), isNull);
664+
665+
// Act
666+
final secondDropdownFinder = find.byWidget(secondDropdown);
667+
await tester.tap(secondDropdownFinder);
668+
await tester.pumpAndSettle();
669+
await tester.tap(find.text('2').last);
670+
await tester.pumpAndSettle();
671+
672+
// Assert
673+
expect(formInstantValue(firstDropdownName), 1);
674+
expect(formInstantValue(secondDropdownName), 2);
675+
expect(formKey.currentState?.fields, contains(firstDropdownName));
676+
expect(formKey.currentState?.fields, contains(secondDropdownName));
677+
});
678+
});
624679
}
625680

626681
// simple stateful widget that can hide and show its child with the intent of

0 commit comments

Comments
 (0)