13

In my TextFormString for Password Field I have validator that returns a String. The problem is this String is too long and it doesn't fit the screen.

I'd like to make it multiline, but I can't find how to do it: I've tried setting width for the Container this TextFormString is in -- no effect, I've hardcoded newlines \n to my String, it actually worked but I think there must be some other solution to break it to lines more dynamically.

What is the right way to do it?

Screenshot

1 Answer 1

39

You can decorate your TextFormFiled so that the error label has more than 1 lines:

errorMaxLines: 2

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

enter image description here

In this example I didn't set obscureText: true (desiderata for a password field), so that the text is visible.

2
  • Wonderful! Thanks a lot!
    – 06153
    Dec 28, 2018 at 0:42
  • 1
    what if the error message is dynamic, meaning we are unsure about the error message length?
    – iAkshay
    Apr 24, 2020 at 12:46

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.