diff --git a/lib/src/form_builder.dart b/lib/src/form_builder.dart index 9af6b070a..040030fc5 100644 --- a/lib/src/form_builder.dart +++ b/lib/src/form_builder.dart @@ -221,7 +221,11 @@ class FormBuilderState extends State { } void unregisterField(String name, FormBuilderFieldState field) { - assert(_fields.containsKey(name)); + assert( + _fields.containsKey(name), + 'Failed to unregister a field. Make sure that all field names in a form are unique.', + ); + // Only remove the field when it is the one registered. It's possible that // the field is replaced (registerField is called twice for a given name) // before unregisterField is called for the name, so just emit a warning