You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes we want to check if a user has interacted with a form so we can offer him the option to save when e.g. popping the route. Currently this can be quite cumbersome to do by listening to onChange events of every single field and updating some state.
Form has a private flag for this, _hasInteractedByUser, which could provide the required information.
Proposal
There already was a similar issue to expose this method for FormField.
The proposal would be to do the same for Form: expose a boolean getter for the value of _hasInteractedByUser.
This way, it could be easily accessed via a key in e.g. a pop handler.
final key =GlobalKey<FormState>;
Form(
key: key,
// ...
),
final changed = key.currentState!.hasInteractedByUser;
The text was updated successfully, but these errors were encountered:
Just realized that form itself has an onChanged that is called whenever a field changes. It could easily be listened to and just set a flag accordingly when any field has changed.
Use case
Sometimes we want to check if a user has interacted with a form so we can offer him the option to save when e.g. popping the route. Currently this can be quite cumbersome to do by listening to
onChange
events of every single field and updating some state.Form
has a private flag for this,_hasInteractedByUser
, which could provide the required information.Proposal
There already was a similar issue to expose this method for
FormField
.The proposal would be to do the same for
Form
: expose a boolean getter for the value of _hasInteractedByUser.This way, it could be easily accessed via a key in e.g. a pop handler.
The text was updated successfully, but these errors were encountered: