flutter - TextFormField 向后输入值 [Flutter]
问题描述
如下图所示,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)
)
解决方案
您不必在 调用
newcontroller.text
时设置文本。onChanged
默认情况下,您输入的文本TextFormField
分配给newcontroller
.
您收到此错误是因为对于这段代码,
所以,尝试删除下面的代码
setState(() {
newcontroller.text = value;
});
推荐阅读
- sql - 找不到用于清除数据库的 DB2 存储过程
- java - 通过 java stacktrace 搜索 Datadog
- python - DMing 成员加入服务器 - Discord.Py
- java - 所选项目未显示在 Andoid 微调器中
- java - 来自当前 webdriver 的循环中的 Selenium 无效会话 ID
- sql - 如果 SCI.SOURCE="CC" ,并且 SCI.CATEGORY 不应该是“不等待”。我想根据这个附加条件返回记录
- flutter - 在单个 TextField 中为多行下划线 - Flutter/Dart
- java - 如何在 Recyclerview 中将 Picasso 更改为 Glide
- electron - 如何在 Electron JS 中添加工作线程?
- c# - Unity 无法销毁克隆 GameObject