Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InputDecoration errorText must be constant

[dart] Invalid constant value. [dart] Arguments of a constant creation must be constant expressions.

I want to make DropdownButton , but errorText only accept constant variable.

[dart] Invalid constant value.
[dart] Arguments of a constant creation must be constant expressions.

Constant variable means I cannot replace with other text.

Maybe any other way to make DropdownButton validation?

String errorGender = null;

    var _inputGender = InputDecorator(
      decoration: const InputDecoration(labelText: 'Gender', errorText: errorGender),
      isEmpty: data['gender'] == null,
      child: DropdownButtonHideUnderline(
        child: ButtonTheme(
          alignedDropdown: true,
            child: DropdownButton(
              isDense: true,
              value: data['gender'],
              onChanged: (value) => setState(() => data['gender'] = value),
              items: _gender.map((value) {
                return DropdownMenuItem(
                  value: value,
                  child: Text(value[0].toUpperCase() + value.substring(1)),
                );
              }).toList()
            )
        )
      )
    );
like image 460
gersur Avatar asked Oct 09 '18 09:10

gersur


People also ask

What is invalid constant value?

In dart when you pass something as a parameter in a const constructor, the compiler makes sure that the value set as default is not changed during the execution of the code. Hence, the Invalid constant value warning. To resolve this issue you should remove the const keyword from the in front of the Text.

What is InputDecoration in flutter?

InputDecoration class Null safety The border, labels, icons, and styles used to decorate a Material Design text field. The TextField and InputDecorator classes use InputDecoration objects to describe their decoration.

How do you decorate a text field in flutter?

By default, a TextField is decorated with an underline. You can add a label, icon, inline hint text, and error text by supplying an InputDecoration as the decoration property of the TextField . To remove the decoration entirely (including the underline and the space reserved for the label), set the decoration to null.


1 Answers

Remove const before InputDecoration

decoration: InputDecoration(labelText: 'Gender', errorText: errorGender)
like image 83
Andrey Turkovsky Avatar answered Oct 24 '22 02:10

Andrey Turkovsky