Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextField: "autocorrect: false" still shows suggestions in keyboard #22828

Closed
sir-boformer opened this issue Oct 8, 2018 · 41 comments · Fixed by #42550
Closed

TextField: "autocorrect: false" still shows suggestions in keyboard #22828

sir-boformer opened this issue Oct 8, 2018 · 41 comments · Fixed by #42550
Assignees
Labels
a: text input Entering text in a text field or keyboard related problems c: new feature Nothing broken; request for a new capability customer: amplify engine flutter/engine repository. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically

Comments

@sir-boformer
Copy link
Contributor

Flutter version: Very recent master build

Happens in the Android Emulator (with Google Keyboard) and on a real Android device (with Sony keyboard). I'm not sure about iOS.

Code to reproduce:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_playground/text_area.dart';
import 'package:path/path.dart' as path;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Playground',
      home: AutoCorrectTest(),
    );
  }
}

class AutoCorrectTest extends StatefulWidget {
  @override
  _AutoCorrectTestState createState() => _AutoCorrectTestState();
}

class _AutoCorrectTestState extends State<AutoCorrectTest> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('TextField with autocorrect: false'),
      ),
      body: Padding(
        padding: EdgeInsets.all(16.0),
        child: TextField(
          autocorrect: false
        )
      ),
    );
  }
}
[√] Flutter (Channel master, v0.9.7-pre.61, on Microsoft Windows [Version 10.0.17134.285], locale de-DE)
    • Flutter version 0.9.7-pre.61 at C:\flutter
    • Framework revision 2d81adf74c (3 days ago), 2018-10-05 22:29:37 -0700
    • Engine revision 572fa5646a
    • Dart version 2.1.0-dev.6.0.flutter-c6254163dc

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at F:\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = F:\Android\sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[√] Android Studio (version 3.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 29.0.2
    • Dart plugin version 181.5616
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[!] VS Code, 64-bit edition
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
@sir-boformer sir-boformer changed the title TextField: "autocorrect: false" is ignored on Android TextField: "autocorrect: false" still shows suggestions in keyboard Oct 8, 2018
@zoechi zoechi added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Oct 9, 2018
@zoechi zoechi added this to the Goals milestone Oct 9, 2018
@sir-boformer
Copy link
Contributor Author

After further investigation, I'm not sure what would be the best way to implement this:

On iOS, autocorrect and keyboard suggestions are directly connected (UITextAutocorrectionTypeNo disables suggestions and autocorrect). In the current version of Flutter, a TextField with autocorrect: false displays no keyboard suggestions on iOS:

https://github.com/flutter/engine/blob/d1c71e5206bd9546f4ff64b7336c4e74e3f4ccfd/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm#L707-L709


On Android, autocorrect and keyboard suggestions can be toggled separately.
I guess this is more or less a new feature, because suggestions and autocorrect are two separate things:

  • InputType.TYPE_TEXT_FLAG_AUTO_CORRECT to enable autocorrect
  • InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS to disable suggestions

Here is how the flags are currently set by flutter:

https://github.com/flutter/engine/blob/d1c71e5206bd9546f4ff64b7336c4e74e3f4ccfd/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java#L93-L99


So for Android it would make sense to add a new property bool keyboardSuggestions to TextField and TextFormField. In the documentation, it should be noted that on iOS setting either autocorrect: false or keyboardSuggestions: false disables both features.

@goderbauer goderbauer added the platform-android Android applications specifically label Jan 3, 2019
@mploigt
Copy link

mploigt commented Jan 29, 2019

I have the same problem implementing a textfield without the suggestion bar on android. For my app the user can input specific codes that should not be changed with suggestions or autocomplete. The suggestion bar is really not helpful in this situation and I can't disable it on android.

Any idea on when the feature to disable the suggestion bar on android will be implemented?

@josvos
Copy link

josvos commented Feb 16, 2019

This technically sounds like pretty "low hanging fruit" for the Flutter dev team (but I might be wrong), but the fact that it is not possible to disable the suggestions in a Flutter app is extremely annoying for app developers.

@daveparks23
Copy link

Any update on this... I am having the same problem. Love Flutter!

@jonahwilliams jonahwilliams added the c: regression It was better in the past than it is now label Mar 19, 2019
@OscarEReyes
Copy link

Any update on this?
Predictive text ruins my textfields.
Highlighting a textfield with text inside and typing results in duplicated text.
Awful for UX.

This is fixed locally for me by turning off predictive text... can't expect that of users....

@Piinks
Copy link
Contributor

Piinks commented Apr 1, 2019

On Android, autocorrect and keyboard suggestions can be toggled separately.
I guess this is more or less a new feature, because suggestions and autocorrect are two separate things:

  • InputType.TYPE_TEXT_FLAG_AUTO_CORRECT to enable autocorrect
  • InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS to disable suggestions

Here is how the flags are currently set by flutter:

https://github.com/flutter/engine/blob/d1c71e5206bd9546f4ff64b7336c4e74e3f4ccfd/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java#L93-L99

I've looked into this and it seems that the InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS doesn't actually dismiss the keyboard suggestions on the Android platform. There is also a comment here that:

// Some devices ignore TYPE_TEXT_FLAG_NO_SUGGESTIONS.

Why this is the case may be the root of the problem.

@Piinks Piinks closed this as completed Apr 1, 2019
@Piinks Piinks reopened this Apr 1, 2019
@Piinks Piinks added the engine flutter/engine repository. See also e: labels. label Apr 1, 2019
@dnfield
Copy link
Contributor

dnfield commented Apr 24, 2019

Are we positive that this is a real regression? Is it possible that @sir-boformer is testing this on a device that doesn't respect the flag?

@cbracken
Copy link
Member

@dnfield agreed, this is not a regression. I did the initial implementation on Android and iOS and the difference would have been an oversight on my part. As suggested above, I think the answer is that we add additional API and document the platform differences between iOS and Android.

@cbracken cbracken added c: new feature Nothing broken; request for a new capability and removed c: regression It was better in the past than it is now labels Apr 29, 2019
@markmoskalenko
Copy link

Help solve the problem! Our release is delayed because of this.

Here is a similar problem #19743
A year has passed ..

@OscarEReyes
Copy link

Hey @markmoskalenko ,

I see the issue you are referencing and I experienced something similar.

The issue was if I selected a text field that had text in it and started typing the text would duplicate and add the character typed.

Ex:

You have the word fire in the text field
You select it and type t

Now it has firefiret in it.

Now that looked similar to issue 19743 so if this is also bothering you, I can help you fix it as I implemented a workaround in my app.

@markmoskalenko
Copy link

@OscarEReyes

Very worried!
Please tell me how to get around this ?!

@OscarEReyes
Copy link

@OscarEReyes

Very worried!
Please tell me how to get around this ?!

I went ahead and commented on issue #19743 on how to solve this.
Let me know if it works.

@amreniouinnovent
Copy link

amreniouinnovent commented Jul 8, 2019

Temporary solution
keyboardType: TextInputType.emailAddress
*Update: not working with all devices

@riposteX
Copy link

This is a bug.

Assuming earlier comments have identified the correct source code, InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS is only being added when obscureText is true, not when autocorrect is false

I've verified on my Pixel 3 that setting obscureText = true does disable keyboard suggestions, whereas setting autocorrect = false does not.

@mikeesouth
Copy link

This is a bug.

Assuming earlier comments have identified the correct source code, InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS is only being added when obscureText is true, not when autocorrect is false

I've verified on my Pixel 3 that setting obscureText = true does disable keyboard suggestions, whereas setting autocorrect = false does not.

Nice catch. This works for me too but obscureText have several negative effects in my case (using a Huawei Mate 20 Pro with Android 9 and Swiftkey keyboard):

  • obscures the text
  • on my phone it displays the numbers row above the default keyboard instead of suggestions
  • on my phone it prevents swipe typing

Is anyone working on a bug fix/PR for the Inputype flag?

@KristineTrona
Copy link

I am experiencing the same issue also on ios - autoCorrect={false} seems to work on simulator, but in a release build on a device it was not working. Is there no way to disable the keyboard suggestions?

@mikeesouth
Copy link

I am experiencing the same issue also on ios - autoCorrect={false} seems to work on simulator, but in a release build on a device it was not working. Is there no way to disable the keyboard suggestions?

You can set obscureText=true but that have some negative effects as stated above.

But I agree - is there any progress on this issue?

@justinmc
Copy link
Contributor

I just opened two PRs for this: #42550 and flutter/engine#13099

I'm pretty much following exactly what @sir-boformer wrote in his analysis above (thank you for that by the way!). I added a flag that only affects Android called noSuggestions, and I commented about the fact that it doesn't affect iOS:

  /// This flag only affects Android. On iOS, suggestions are tied directly to
  /// [autocorrect], so that suggestions are only shown when [autocorrect] is
  /// true. On Android autocorrection and suggestion are controlled separately.

@RudolfVonKrugstein
Copy link

How cannot find the option to disable suggestions. What am I missing? Why is this closed?

@Piinks
Copy link
Contributor

Piinks commented Nov 22, 2019

Hi @RudolfVonKrugstein, what version of Flutter are you using?

@atreeon
Copy link

atreeon commented Dec 3, 2019

Hi @Piinks, I'm having the same problem. Am I doing something wrong?

I am on the very latest master branch (v1.12.17-pre.38) but I'm getting the following result (ie suggestions)

Screenshot 2019-12-03 at 12 49 29

with the following code


          TextField(
            enableSuggestions: false,
            autocorrect: false,
            autofocus: false,
            keyboardType: TextInputType.text,
          ),

@Piinks
Copy link
Contributor

Piinks commented Dec 3, 2019

cc/ @justinmc who worked on the fix for this. I haven't reproduced it yet on master.

@MOlechowski
Copy link

@atreeon @RudolfVonKrugstein Try with this

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

@atreeon
Copy link

atreeon commented Dec 9, 2019

Hi @MichalOlechowskiDev, 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. The result is what I am after though so thank you!

@mikeesouth
Copy link

@atreeon @RudolfVonKrugstein Try with this

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

Thanks, this helps. I think that setting any form om password input type will prevent swiping functionality on keyboards that supports it, e.g. stock android and swiftkey. Not sure though and I haven't tested it.

I was expecting it to work like this:

  • Swiping would work for all non-password prompt
  • autocorrect would autocorrect words when swiping or tapping letters
  • enableSuggestions would show/hide the top row with suggested (predicted) words

If that is correct I would like to set a non password type of keyboard, enable autocorrect and disable suggestions.

@justinmc
Copy link
Contributor

Gboard ignores the TYPE_TEXT_FLAG_NO_SUGGESTIONS flag in some situations (see this StackOverflow post), which is what is controlled by the enableSuggestions parameter in Flutter.

We want to provide a nice platform-independent API and not just create a parameter for every native flag, but we also might not want to special-case things for Gboard in the engine. I'm not sure if there's a clear improvement to be made here, but I'm definitely interested if someone has a proposal.

@deandreamatias
Copy link

Gboard ignores the TYPE_TEXT_FLAG_NO_SUGGESTIONS flag in some situations (see this StackOverflow post), which is what is controlled by the enableSuggestions parameter in Flutter.

We want to provide a nice platform-independent API and not just create a parameter for every native flag, but we also might not want to special-case things for Gboard in the engine. I'm not sure if there's a clear improvement to be made here, but I'm definitely interested if someone has a proposal.

In this case, is better reopen the issue?

@riposteX
Copy link

This still doesn't do what I want.

As noted above, the enableSuggestions flag appears to do nothing by itself. Only when paired with keyboardType: TextInputType.visiblePassword do the suggestions go away.

However, now other options, such as textCapitalization: TextCapitalization.words are ignored.

These are my main requirements - no suggestions (preferably without any space wasting empty grey box or numbers which appear with visiblePassword), and capitalized words. Is there anyway to achieve this currently in flutter?

@justinmc
Copy link
Contributor

@kevinengel Can you achieve that in native Android, and if so what flags do you use?

@riposteX
Copy link

Good point, same issue does occurs with Android, please ignore my last post. Guess it's just a keyboard issue (though c'mon Pixel 3, I feel like you of all phones should be supporting all the Android features ...)

@justinmc
Copy link
Contributor

Gboard definitely seems to be doing some non-intuitive things based on the flags that are given.

@cihadturhan
Copy link

Any chance on reopening this issue?

I'm having this issue on Huawei mate and setting keyboardType: TextInputType.visiblePassword is not an option for me because I have to use TextInputType.multiline.

I don't want user to use autocomplete because they might enter non-word texts.
Also, if I use TextInputType.visiblePassword, enter button on keyboard doesn't work as expected. So it's not a viable option.

@dnfield
Copy link
Contributor

dnfield commented May 15, 2020

@cihadturhan you would have better luck filing a specific issue for Huawei devices with reproduction instructions.

@louia
Copy link

louia commented May 25, 2020

May 2020, flutter stable 1.17.1, still experimenting this issue with default samsung's keyboard (S8) and with this code :

TextField(
          autocorrect: false,
          enableSuggestions: false,
          autofocus: false
)

PLEASE RE OPEN

@justinmc
Copy link
Contributor

@louia Can you achieve what you want with a native Android app? If so, how? See #22828 (comment)

If you can reproduce a case that is possible in native Android but not possible in Flutter given the flags being set, go ahead and open a separate issue with reproduction steps. Please tag me and I'll be interested to see what's going on.

@PhamTruongHung
Copy link

PhamTruongHung commented Aug 30, 2020

@atreeon @RudolfVonKrugstein Try with this

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

That's work on Flutter 1.20.2, iOS device.

@nicolasfavier
Copy link

I am facing the same issue,
I want to have a multiple lines TextField without suggestions.

Ios work just fine using :
keyboardType: TextInputType.multiline, enableSuggestions: false, autocorrect: false,

But in an android device I still have the suggestions.

In Android natif you can get this using :
android:inputType="textFilter|textMultiLine|textNoSuggestions"

@louia do you want me to open a new issue ?

@justinmc
Copy link
Contributor

justinmc commented Dec 1, 2020

@nicolasfavier I say yes, please open a new issue with this info! Someone can double check whether or not those exact inputType flags you mentioned are being set by the Flutter engine.

@github-actions
Copy link

github-actions bot commented Aug 9, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: text input Entering text in a text field or keyboard related problems c: new feature Nothing broken; request for a new capability customer: amplify engine flutter/engine repository. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically
Projects
None yet
Development

Successfully merging a pull request may close this issue.