Closed BenjiFarquhar closed 9 months ago
Hi. Thanks for this finding and for contribution This definitely makes sense.
released
Hi @BenjiFarquhar! Your issue has been closed. If we were helpful don't forget to star the repo.
Please check our reactive_forms_widget package
We would appreciate sponsorship subscription or one time donation https://github.com/sponsors/artflutter
I've noticed reassigning the formModel in didUpdateWidget is problematic for anything other than example forms. Subscriptions are lost, and other weird things happen by replacing the form with a completely new form. Forms should live as long as the widget lives because they have too many tentacles into other components via subscriptions, which get lost when the form is reassigned. Validators start validating the wrong form controls that are no longer in use. reactive_forms_lbc widgets start acting strange. Forms are not immutable objects, nor should they be, so they shouldn't be treated like it by reassigning them.
Solution: Mutate the form. A quick and easy solution is to use
formModel.updateValue
, where you reassign the form. TheupdateValue
value
param will need a null-aware operator. You can then get rid of_formModel.form.markAsDisabled()
andwidget.initState?.call(context, _formModel)
as none of the original form state will be lost lost.E.g.:
Will become:
and
Will become: