如何禁用Flutter的TextField中的预测文本?

时间:2019-03-14 07:44:48

标签: flutter

我想禁用文本字段键盘中的预想文本。在本地android和IOS中并不是那么困难,但是我没有在flutter中找到解决方案。

我尝试使用自动更正:false和更改键盘类型,但是它不起作用。

TextField(
          autocorrect: false,
          keyboardType: TextInputType.emailAddress,
          decoration: new InputDecoration(hintText: "Enter text"),
          autofocus: true,
        ),

5 个答案:

答案 0 :(得分:9)

如果enableSuggestionsautocorrect都不能解决问题,请尝试将keyboardType设置为 TextInputType.visiblePassword

答案 1 :(得分:3)

您可以尝试将enableSuggestions = false添加到文本字段窗口小部件。这样应该可以https://github.com/flutter/flutter/pull/42550禁用键盘上的预想文本。

TextField(
      autocorrect: false,
      enableSuggestions: false,
      keyboardType: TextInputType.emailAddress,
      decoration: new InputDecoration(hintText: "Enter text"),
      autofocus: true,
    ),

答案 2 :(得分:0)

在撰写此答案时,Android尚不可用。但是使用自动更正:在iOS上为false应该可以正常工作。

检查:https://github.com/flutter/flutter/issues/22828

答案 3 :(得分:0)

这在iOS和android上都对我有用

                    TextField(
                        autocorrect: false,
                        obscureText: true,
                        controller: answerText,
                        textAlign: TextAlign.center,
                        keyboardType: TextInputType.text,
                        textInputAction: TextInputAction.done,
                        autofocus: true,
                        onChanged: (value) {
                          setState(() {
                            result = value;
                          });
                        },),

唯一的缺点是它使屏幕上的内容模糊不清。一种解决方法是在屏幕Text(result)

中添加一个位置

答案 4 :(得分:0)

因为没有具体的解决方案,现在尝试用这种方式

TextField(
  enableSuggestions: false,
  keyboardType: TextInputType.visiblePassword
)

确实可以。我想说的是,它并不那么明显,enableSuggestions似乎也根本没有改变行为(只是keyboardType属性),而当keyboardType时,这不起作用设置为visiblePassword以外的其他值

相关问题