Notification texts go here Contact Us Buy Now!

Multiline string for TextFormString validator

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;
  },
)

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.