How to disable predictive text in TextField of Flutter?

12,808

Solution 1

If neither enableSuggestions nor autocorrect can solve the problem, try setting keyboardType to TextInputType.visiblePassword.

Solution 2

You can try to add enableSuggestions = false to your textfield widget. This should disable the predictive text from your keyboard as supposed to https://github.com/flutter/flutter/pull/42550.

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

Solution 3

For now try to do it this way because there is no concrete solution yet

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

That does indeed work. I would say that it isn't so obvious and also enableSuggestions doesn't seem to alter the behaviour at all (just the keyboardType property) and this doesn't work when the keyboardType is set to anything else other than visiblePassword

Solution 4

At the time of writing this answer, this is not yet available in Android. But using autocorrect: false on iOS should work fine.

Check: https://github.com/flutter/flutter/issues/22828

Solution 5

This worked for me on both iOS and android

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

The only downside is that it obscure from the screen what is written. A workaround is to add somewhere in the screen Text(result)

Share:
12,808
sk_462
Author by

sk_462

Updated on June 05, 2022

Comments

  • sk_462
    sk_462 almost 2 years

    I want to disable predictive text which comes in the keyboard of a textfield. It is not so difficult in native android and IOS but I have not found a solution in a Flutter.

    I have tried using autocorrect: false and changing keyboardtypes but it is not working.

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