You can add more than 1 line to your TextFormFiled
error label by using the errorMaxLines
property in the InputDecoration
:
errorMaxLines: 2
For example:
TextFormField(
decoration: const InputDecoration(
icon: Icon(Icons.person),
hintText: 'What do people call you?',
labelText: 'Name *',
errorMaxLines: 2
),
validator: (String value) {
return value.contains('@')
? 'Do not use the @ char. Do not use the @ char. Do not use the @ char. Do not use the @ char.'
: null;
},
),
In this instance, obscureText
is set to true
to hide the text, which is necessary for a password field.
In newer versions, errorMaxLines
can be added directly to InputDecoration
:
TextFormField(
decoration: InputDecoration(
errorMaxLines: 2,
),
validator: (value) {
if (value.isEmpty) {
return 'Please Enter Something';
}
return null;
},
)