Skip to content

Instantly share code, notes, and snippets.

@bettdouglas
Created June 19, 2019 13:40
Show Gist options
  • Save bettdouglas/dbb5ac36e7b8493882b7ee41f74ea8ae to your computer and use it in GitHub Desktop.
Save bettdouglas/dbb5ac36e7b8493882b7ee41f74ea8ae to your computer and use it in GitHub Desktop.
var _formKey = GlobalKey<FormState>();
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
DynamicInput(
hint: 'Enter valid name',
controller: nameController,
label: 'Name',
type: DataType.NAME,
),
DynamicInput(
hint: 'Enter valid email',
controller: emailController,
label: 'Email',
type: DataType.EMAIL,
),
DynamicInput(
hint: 'Enter valid age',
controller: ageController,
label: 'Age:',
type: DataType.INTEGER,
),
DynamicInput(
hint: 'Enter valid phone',
controller: phoneController,
label: 'Phone',
type: DataType.PHONE,
),
RaisedButton(
child: Text('Validate'),
color: valid ? Colors.green : Colors.red,
onPressed: () {
if (_formKey.currentState.validate()) { ///validates the form
setState(() {
valid = true;
});
print('Entire form is valid');
} else {
print('Some info is not correct');
}
},
)
],
),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment