TextFormField向后输入值[Flutter] [英] TextFormField enters value backwards [Flutter]

查看:71
本文介绍了TextFormField向后输入值[Flutter]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

As displayed in the GIF below, the TextFormField i am using is entering the values backwards. I have set the TextDirection property to ltr as well but it did not change anything. Other TextFormFields dont seem to be having this issue. The entered text is being sent back to another screen using Navigator.pop and it is sent in the same backwards manned.

奇怪的TextFormField

导致问题的textFormField的代码:

Code for the textFormField causing the issue:

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)
)

推荐答案

您可以在 Navigator.pop(上下文,无论您要传递的是什么)中发送任意内容

  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!"),
              ), 

这篇关于TextFormField向后输入值[Flutter]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆