TextFormField向后输入值[Flutter]
TextFormField enters value backwards [Flutter]
如下面的 GIF 所示,我使用的 TextFormField
正在向后输入值。我也将 TextDirection
属性 设置为 ltr
但它没有改变任何东西。其他 TextFormFields
似乎没有这个问题。输入的文本正在使用 Navigator.pop
发送回另一个屏幕,并以相同的向后人工发送。
Weird 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)
)
you can send whatever you want in Navigator.pop(context,whatever you want to pass)
TextFormField(
// validator: (String value) {
// return value.isEmpty ? "task must have a name" : null;
// },
textAlign: TextAlign.end,
maxLength: 100,
controller: newcontroller, // Just an ordinary TextController
onChanged: (value) {
print(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),
),
MaterialButton(
onPressed: () {
Navigator.pop(context, newcontroller.text);
},
child: Text("GO BACK!"),
),
只需删除 onChanged 函数即可。没必要。
You don't have to set text in newcontroller.text
when onChanged
is called.
text enter in your TextFormField
is assigned by default to newcontroller
.
您收到此错误是因为对于这段代码,
所以,尝试删除下面的代码
setState(() {
newcontroller.text = value;
});
将 onChanged 替换为 onEditingComplete。
onEditingComplete: (value) {
newController.text = value;
FocusScope.of(context).unfocus(); //use this to dismiss the screen keyboard
}
如下面的 GIF 所示,我使用的 TextFormField
正在向后输入值。我也将 TextDirection
属性 设置为 ltr
但它没有改变任何东西。其他 TextFormFields
似乎没有这个问题。输入的文本正在使用 Navigator.pop
发送回另一个屏幕,并以相同的向后人工发送。
Weird 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)
)
you can send whatever you want in Navigator.pop(context,whatever you want to pass)
TextFormField(
// validator: (String value) {
// return value.isEmpty ? "task must have a name" : null;
// },
textAlign: TextAlign.end,
maxLength: 100,
controller: newcontroller, // Just an ordinary TextController
onChanged: (value) {
print(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),
),
MaterialButton(
onPressed: () {
Navigator.pop(context, newcontroller.text);
},
child: Text("GO BACK!"),
),
只需删除 onChanged 函数即可。没必要。
You don't have to set text in
newcontroller.text
whenonChanged
is called. text enter in yourTextFormField
is assigned by default tonewcontroller
.
您收到此错误是因为对于这段代码,
所以,尝试删除下面的代码
setState(() {
newcontroller.text = value;
});
将 onChanged 替换为 onEditingComplete。
onEditingComplete: (value) {
newController.text = value;
FocusScope.of(context).unfocus(); //use this to dismiss the screen keyboard
}