validation text field flutter code example
Example 1: text input validation message color flutter
TextFormField(
decoration: InputDecoration(
errorStyle: TextStyle(
color: Colors.red[400],
fontWeight: FontWeight.bold,
fontSize: 13,
),
),
...
)
Example 2: create a validator in flutter
TextFormField(
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
);
Example 3: create a validator in flutter
ElevatedButton(
onPressed: () {
if (_formKey.currentState.validate()) {
Scaffold
.of(context)
.showSnackBar(SnackBar(content: Text('Processing Data')));
}
},
child: Text('Submit'),
);