Skip to content

Commit 9fdc973

Browse files
authored
Merge pull request #542 from awhitford/field_dups
Added assertions to warn against improper field registration.
2 parents 3b89abc + 9092da1 commit 9fdc973

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/src/form_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class FormBuilder extends StatefulWidget {
7373
}
7474

7575
class FormBuilderState extends State<FormBuilder> {
76-
//TODO: Find way to assert no duplicates in field names
7776
final _formKey = GlobalKey<FormState>();
7877

7978
Map<String, FormBuilderFieldState> _fields;
@@ -114,10 +113,12 @@ class FormBuilderState extends State<FormBuilder> {
114113
}
115114

116115
void registerField(String name, FormBuilderFieldState field) {
116+
assert(!_fields.containsKey(name));
117117
_fields[name] = field;
118118
}
119119

120120
void unregisterField(String name) {
121+
assert(_fields.containsKey(name));
121122
_fields.remove(name);
122123
}
123124

0 commit comments

Comments
 (0)