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

35

我想在文本框的键盘中禁用预测文本。在原生Android和IOS中并不难,但我在Flutter中没有找到解决方案。

我尝试使用autocorrect: false和更改keyboardtypes,但它没有起作用。

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

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

2
TextInputType.visiblePassword 可以使用,但我需要在键盘中添加多行按钮。 - Xihuny
1
enableSuggestions: false 对我有用。谢谢。 - speksy

22
您可以尝试在文本字段小部件中添加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,
    ),

4

3
这对我来说在iOS和安卓上都有效。
                    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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接