12

[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()
            )
        )
      )
    );
gersur
  • 187
  • 3
  • 10

1 Answers1

44

Remove const before InputDecoration

decoration: InputDecoration(labelText: 'Gender', errorText: errorGender)
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Andrii Turkovskyi
  • 27,554
  • 16
  • 95
  • 105