首页 > 解决方案 > TextFormField 向后输入值 [Flutter]

问题描述

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

奇怪的 TextFormField

导致问题的 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)
)

标签: fluttertextfielddirection

解决方案


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

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

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

 setState(() {
            newcontroller.text = value;
        });

推荐阅读