Repository navigation
[proposal] Provide a way to retrieve the data of all textfields within a Form widget #107528
Description
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
pedromassango commentedon Jul 13, 2022
So this ticket is about adding a way to retrieve the data of all fields?
casvanluijtelaar commentedon Jul 13, 2022
yes, All FormField descendants of this Form widget with a valid submissionKey
[-]Add form submit functionality [/-][+][proposal] Provide a way to retrieve the data of all textfields within a `Form` widget[/+]5 remaining items
fngadiyo commentedon Sep 25, 2024
2 years later, still no plan for this.
Henry-Hiles commentedon May 24, 2025
This is quite handy for large or generated forms, is there a plan for this to be implemented soon?
Mairramer commentedon Jan 9, 2026
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 theFormStatein a structured way, usingValueKeys as identifiers.Example:
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.Add fields getter to FormState (#180815)
Add fields getter to FormState (flutter#180815)
github-actions commentedon Mar 7, 2026
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 -vand a minimal reproduction of the issue.Add fields getter to FormState (flutter#180815)
Add fields getter to FormState (#180815)