Recall & Review
beginner
What is the purpose of the
Form widget in Flutter?The
Form widget groups multiple form fields together and helps manage their validation and saving as a single unit.Click to reveal answer
beginner
What is a
GlobalKey used for in Flutter forms?A
GlobalKey uniquely identifies the FormState so you can access and control the form (like validating or saving) from outside the form widget.Click to reveal answer
intermediate
How do you validate all fields inside a Flutter
Form?Call
_formKey.currentState!.validate() where _formKey is the GlobalKey<FormState>. It runs all validators and returns true if all pass.Click to reveal answer
intermediate
Why should you use a
GlobalKey<FormState> instead of a local key for a form?Because
GlobalKey allows you to access the form's state from anywhere in the widget tree, enabling actions like validation and saving outside the form widget.Click to reveal answer
intermediate
What happens if you call
_formKey.currentState!.save() in Flutter?It triggers the
onSaved callbacks of all form fields inside the form, allowing you to store or process the input values.Click to reveal answer
What type should a
GlobalKey have to manage a Flutter form?✗ Incorrect
The
GlobalKey must be typed as GlobalKey<FormState> to access the form's state methods like validate() and save().Which method validates all fields inside a Flutter form?
✗ Incorrect
Calling
validate() on the FormState runs all field validators and returns true if all are valid.How do you access the form state from outside the form widget?
✗ Incorrect
A
GlobalKey<FormState> allows you to access the form state anywhere, unlike local keys or BuildContext.What does the
onSaved callback do in a form field?✗ Incorrect
onSaved is called during FormState.save() to store or process the input value.What will
_formKey.currentState!.validate() return if any field is invalid?✗ Incorrect
If any validator returns false,
validate() returns false indicating the form is not valid.Explain how to use a
Form widget with a GlobalKey to validate user input in Flutter.Think about how you connect the key to the form and trigger validation.
You got /4 concepts.
Describe the role of
onSaved callbacks in Flutter forms and how they work with GlobalKey.Consider when and how the form fields save their data.
You got /4 concepts.