Skip to content

[proposal] Provide a way to retrieve the data of all textfields within a Form widget #107528

Closed

Description

@casvanluijtelaar

Use case

the Flutter Form widget can be extremely powerful and has a lot of potential to simplify form implementations. Sadly I'm finding myself having to create my own Form widgets because there is not simple build-in way to aggregate all the form data in one place. Just like the form can interact with all its FormField children through validation, saving, ... it should also have an option to submit it's childrens data. Similar to how HTML handles form submission.

Proposal

since the FormState already has all its FormFieldState children registered it would be trivial to collect all their values. the implementation difficulties come from returning the form data in a manageable way.

I would propose adding a submissionKey string to the FormField<T> base class. this allows us to aggregate all the FormField data under a Map<String, dynamic> where the entries would be shaped as: submissionKey: value.

this would require all FormField to have a non-null submissionKey. This can be hande by either throwing an exception when calling a form submit on a null submissionKey, or not adding FormField values to the end Form submit data if the submissionKey is null.

This would be a minor addition to the framework with no breaking or changing code, that would still have enormous benefits.

comparing the current closest implementation of this:

Form(
  child: Column(
    children: [
      TextField( 
        onSave: (value) {
          data['name'] = value;
        },
      ),
      TextField(
        onSave: (value) {
          data['email'] = value;
        },
      ),
      TextField(
         onSave: (value) {
          data['message'] = value;
        },
      ),
      MaterialButton(
        child: Text('submit'),
        onPressed: () {
          final form = Form.of(context);
          if(!form.validate()) return;

          form.save();
          /// handle data in stateful widget...
        }
      ),
    ],
  ),    
);

would be turned into something like this:

Form(
  child: Column(
    children: [
      TextField(
        submissionKey: 'name',
        ...
      ),
      TextField(
        submissionKey: 'email',
        ...
      ),
      TextField(
        submissionKey: 'message',
        ...
      ),
      MaterialButton(
        child: Text('submit'),
        onPressed: () {
          final form = Form.of(context);
          if(!form.validate()) return;
          
          final data = form.submit();
          // final object = FormObject.fromJson(data); ...
        }
      );
    ],
  ),    
);

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Jul 13, 2022
  2. pedromassango commented on Jul 13, 2022

    @pedromassango
    Member

    So this ticket is about adding a way to retrieve the data of all fields?

  3. casvanluijtelaar commented on Jul 13, 2022

    @casvanluijtelaar
    Author

    So this ticket is about adding a way to retrieve the data of all fields?

    yes, All FormField descendants of this Form widget with a valid submissionKey

  4. changed the title [-]Add form submit functionality [/-] [+][proposal] Provide a way to retrieve the data of all textfields within a `Form` widget[/+] on Jul 13, 2022
  5. 5 remaining items

  6. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Nov 29, 2023
  7. added
    triaged-designTriaged by Design Languages team
    P3Issues that are less important to the Flutter project
    on Jan 11, 2024
  8. fngadiyo commented on Sep 25, 2024

    @fngadiyo

    2 years later, still no plan for this.

  9. Henry-Hiles commented on May 24, 2025

    @Henry-Hiles

    This is quite handy for large or generated forms, is there a plan for this to be implemented soon?

  10. Mairramer commented on Jan 9, 2026

    @Mairramer
    Contributor

    I’m implementing something that addresses the proposal described in #110760 and also partially covers a related proposal.

    The main idea is to allow extracting the values of all FormFields from the FormState in a structured way, using ValueKeys as identifiers.

    Example:

    final formKey = GlobalKey<FormState>();
    
    Scaffold(
      body: Form(
        key: formKey,
        child: Column(
          children: <Widget>[
            TextFormField(
              key: const ValueKey('name'),
              initialValue: 'Name',
            ),
            TextFormField(
              key: const ValueKey('email'),
              initialValue: 'Email',
            ),
          ],
        ),
      ),
    );
    
    final List<FormFieldState<dynamic>> fields =
        formKey.currentState!.fields.toList();
    
    final data = <String, dynamic>{};
    
    for (final field in fields) {
      final key = field.widget.key;
      if (key is ValueKey<String>) {
        data[key.value] = field.value;
      }
    }
    
    print(data);
    // {name: Name, email: Email}

    This makes it possible to obtain a Map<String, dynamic> representing the current state of the form, without having to keep individual references to each field.

  11. added a commit that references this issue on Feb 21, 2026
    9c8defe
  12. added a commit that references this issue on Feb 27, 2026
    967206b
  13. github-actions commented on Mar 7, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Mar 7, 2026
  15. added a commit that references this issue on Mar 26, 2026
    e426c6d
  16. added a commit that references this issue on Sep 28, 2026
    1461768
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: text inputEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions