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

06153
  • 189
  • 2
  • 9

1 Answers1

37

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.

shadowsheep
  • 14,048
  • 3
  • 67
  • 77