Skip to content

Add getter for FormField's _hasInteractedByUser #131538

@dumazy

Description

@dumazy

Is there an existing issue for this?

Use case

I'm extending the FormFieldState class to create a custom type of form. I've overridden the save method to call another method in the codebase, whenever save is triggered from the wrapping Form. I only want to call this other method if the field has been interacted with.

FormField has a private flag for this, _hasInteractedByUser, which could provide the required information. A way to currently solve this is to override didChange and reset to keep track of my own boolean flag.

Proposal

I would like FormFieldState to expose a boolean getter for the value of _hasInteractedByUser. I see two cases in which this could be useful.

  1. When accessing the FormFieldState via a key.
final key = GlobalKey<FormFieldState<String>>;

TextFormField(
  key: key,
),

final changed = key.currentState!.hasInteractedByUser;
  1. When extending FormFieldState.
@override
void save() {
  super.save();
  if(hasInteractedByUser) {
    doSomethingAwesome();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions