[dart] Invalid constant value. [dart] Arguments of a constant creation must be constant expressions.
我想创建DropdownButton,但是errorText只接受常量。
[dart] Invalid constant value. [dart] Arguments of a constant creation must be constant expressions.
常量变量意味着我不能用其他文本替换。
也许还有其他方法可以进行DropdownButton验证?
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()
)
)
)
);
答案 0 :(得分:11)
在const
之前删除InputDecoration
decoration: InputDecoration(labelText: 'Gender', errorText: errorGender)