TextFormField向后输入值[Flutter]

问题描述 投票:0回答:3

如下面的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)
)
flutter textfield direction
3个回答
2
投票

您可以在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!"),
              ), 

0
投票

只需删除onChanged函数。不需要它。


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.