Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter for Form's _hasInteractedByUser #147462

Closed
mwoelk opened this issue Apr 27, 2024 · 1 comment
Closed

Add getter for Form's _hasInteractedByUser #147462

mwoelk opened this issue Apr 27, 2024 · 1 comment

Comments

@mwoelk
Copy link

mwoelk commented Apr 27, 2024

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.

final key = GlobalKey<FormState>;

Form(
  key: key,
  // ... 
),

final changed = key.currentState!.hasInteractedByUser;
@mwoelk
Copy link
Author

mwoelk commented Apr 27, 2024

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.

Closing because not an issue anymore.

@mwoelk mwoelk closed this as not planned Won't fix, can't repro, duplicate, stale Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant