[General]: Log warning when patchValue
does not find a corresponding registered field
#1407
Open
1 task done
Labels
enhancement
New feature or request
Is there an existing issue for this?
Package/Plugin version
9.3.0
What you'd like to happen
In the
FormBuilderState.patchValue
method, the code takes in the new value map, iteratively search for a registered field with the map key, and calls the field'sdidChange
method if the field is found.Developers that are not familiar with the inner workings with the library may often wrongly assume the
patchValue
method updates the value of the form, regardless whether the FormField is present or not.This is often the case in my team of developers when we are using this library. Since conditional rendering is a very common practice in the Flutter framework, one may do something like this:
This will not work as the field has not yet been registered. The workaround is to either use
Offstage
to make the field always stays inside the widget tree, or to callpatchValue
a frame later usingaddPostFrameCallback
However, debugging this is not easy.
I suggest we can add a warning log when
patchValue
cannot find the respective field using the key inside the map, warning the developer that the field with the given key is not registered and therefore the update to that field is ignored.Alternatives you've considered
No response
Aditional information
No response
The text was updated successfully, but these errors were encountered: