September 2019
Beginner
512 pages
12h 52m
English
We must add the Form widget to our layout to be capable of validating all the fields at once during saving. This is done by simply wrapping our form field widgets with a Form widget. We also set the key property of our Form with a GlobalKey instance (_formKey in the State object of the following code) so that we can use it later in the save() method:
class RequestFavorPageState extends State<RequestFavorPage> { final _formKey = GlobalKey<FormState>(); @override Widget build(BuildContext context) { // returns the widget subtree wrapped in a Form. hidden for brevity. }}
The save() method looks similar to previous ones:
FlatButton( child: Text("SAVE"), textColor: Colors.white, onPressed: () { RequestFavorPageState.of(context).save(); ...Read now
Unlock full access