在 Flutter 中将 Var 传递给常量参数

Pass a Var to Constant Parameter in Flutter

当我写这段代码时,

        TextFormField(
              cursorRadius: Radius.circular(26),
              cursorColor: Colors.green,
              onChanged: onTextInChange,
              textInputAction: TextInputAction.search,
              decoration: const InputDecoration(
                border: UnderlineInputBorder(),
                labelText: texts.toForm[0],
                hintText: texts.toForm[1],
                helperText: texts.toForm[2],
                labelStyle: TextStyle(fontSize: 18),
                hintStyle: TextStyle(fontSize: 18),
              ),
            )

我的文本 Class是这样的,

class Texts{
   let toForm = ['Enter Your Name', 'John Fernando', 'This is a Helper Text'];
}

我收到一个错误,

Invalid constant value.dart(invalid_constant)

这些 helperTexthintTexthelperText 需要常量字符串,但我想使用列表通过 class 传递它们,而不是直接指定值。

那么,我该怎么办?

请帮帮我!我是 Flutter 和 Dart 的新手!!!

从父项中删除 constInputDecoration

        TextFormField(
          cursorRadius: Radius.circular(26),
          cursorColor: Colors.green,
          onChanged: onTextInChange,
          textInputAction: TextInputAction.search,
          decoration: InputDecoration(
            border: UnderlineInputBorder(),
            labelText: texts.toForm[0],
            hintText: texts.toForm[1],
            helperText: texts.toForm[2],
            labelStyle: TextStyle(fontSize: 18),
            hintStyle: TextStyle(fontSize: 18),
          ),
        )