TextFormField 向后输入值 [Flutter]

4 textfield direction flutter

正如下面的 GIF 所示,TextFormField我正在使用的是向后输入值。我也将TextDirection属性设置为ltr,但它没有改变任何东西。其他TextFormFields似乎没有这个问题。输入的文本被发送回另一个屏幕Navigator.pop,并以相同的向后有人发送。

奇怪的文本表单字段

导致问题的 textFormField 代码:

TextFormField(
// validator: (String value) {
// return value.isEmpty ? "task must have a name" : null;
// },
    textDirection: TextDirection.ltr,
    maxLength: 100,
    controller: newcontroller, // Just an ordinary TextController
    onChanged: (value) {
        setState(() {
            newcontroller.text = value;
        });
    },
    decoration: InputDecoration(
        errorText: _validate  // Just a boolean value set to false by default
                   ? 'Value Can\'t Be Empty' : null,
        labelText: "name of task"
    ),
    style: TextStyle(height: 1.2, fontSize: 20, color: Colors.black87)
)
Run Code Online (Sandbox Code Playgroud)

Rav*_*mar 11

您不必在 调用newcontroller.text时设置文本。默认情况下,onChanged您输入的文本会分配给。TextFormFieldnewcontroller

您收到此错误是因为对于这段代码,

所以,尝试删除下面的代码

 setState(() {
            newcontroller.text = value;
        });
Run Code Online (Sandbox Code Playgroud)