final _formKey =GlobalKey<FormState>();@overrideWidgetbuild(BuildContext context) {// Build a Form widget using the _formKey created above.returnForm( key: _formKey, child:Column( children:<Widget>[// Add TextFormFields and RaisedButton here. ] ) ); }}
TextFormField(// The validator receives the text that the user has entered. validator: (value) {if (value.isEmpty) {return'Please enter some text'; }returnnull; },);
RaisedButton( onPressed: () {// Validate returns true if the form is valid, otherwise false.if (_formKey.currentState.validate()) {// If the form is valid, display a snackbar. In the real world,// you'd often call a server or save the information in a database.Scaffold .of(context) .showSnackBar(SnackBar(content:Text('Processing Data'))); } }, child:Text('Submit'),);