Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline string for TextFormString validator

Tags:

flutter

dart

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

like image 224
06153 Avatar asked Dec 27 '18 09:12

06153


1 Answers

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.

like image 105
shadowsheep Avatar answered Nov 07 '22 05:11

shadowsheep