Skip to content

Instantly share code, notes, and snippets.

@pedromassango
Created July 8, 2020 10:48
Show Gist options
  • Save pedromassango/edb4b3d2fdef8524e7a2e6f1d664aee7 to your computer and use it in GitHub Desktop.
Save pedromassango/edb4b3d2fdef8524e7a2e6f1d664aee7 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
//final GlobalKey<FormState> _formState = GlobalKey();
final GlobalKey<FormFieldState> _formFieldState = GlobalKey();
runApp(MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Scaffold(
body: Center(
child: Form(
//key: _formState,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(
children: [
TextFormField(
key: _formFieldState,
validator: (value) {
return 'error1:$value';
},
),
TextFormField(
validator: (value) {
return 'error2:$value';
},
),
TextFormField(
validator: (value) {
return 'error3:$value';
},
),
],
),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.refresh),
onPressed: () {
_formFieldState.currentState.reset();
},
),
),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment