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

Flutter OnScreen Keyboard opens on physical key press #51478

Closed
SebastianRuettger opened this issue Feb 26, 2020 · 21 comments · Fixed by flutter/engine#49829
Closed

Flutter OnScreen Keyboard opens on physical key press #51478

SebastianRuettger opened this issue Feb 26, 2020 · 21 comments · Fixed by flutter/engine#49829
Labels
a: text input Entering text in a text field or keyboard related problems e: device-specific Only manifests on certain devices framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project r: fixed Issue is closed as already fixed in a newer version team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@SebastianRuettger
Copy link

I have a device that uses a laserscanner to scan barcodes and outputs the result as simulated keypresses. I've used this with a RawKeyboardListener and it worked fine. Since then I've added a login screen to the app, that is only shown if the user hasn't logged in. If the login screen has been shown and disposed the onscreen keyboard opens when i press the physical scanner button. This should not happen and doesn't happen if the login screen hasn't been shown. My guess is, that there still are some remains of the textfields used in the login screen, after it is disposed. I've tried setting the FocusNodes for the Textfields and then disposing them in the dispose method, but that didn't work

I've asked a question on StackOverflow: https://stackoverflow.com/questions/60417173/flutter-onscreen-keyboard-opens-on-physical-key-press

Steps to Reproduce

  1. Screen with one or more Textfields
  2. focus one or more
  3. navigate to new screen
  4. press physical button

Expected results: button is pressed but only the keyevents are fired

Actual results: the onscreen keyboard opens

Logs
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.16299.1686], locale de-DE)
    • Flutter version 1.12.13+hotfix.8 at C:\Users\sruettge\Documents\flutter
    • Framework revision 0b8abb4724 (2 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
    • Android SDK at C:\Users\sruettge\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 36.0.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.42.1)
    • VS Code at C:\Users\sruettge\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.8.1

[√] Connected device (1 available)
    • MEMOR 10 • S19H00332 • android-arm64 • Android 8.1.0 (API 27)

• No issues found!
@VladyslavBondarenko VladyslavBondarenko added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Feb 26, 2020
@artemtkachenko
Copy link

Same issue
I am really disappointed since it blocks flutter development for android applications that have a virtual keyboard but does not have a touch screen.
It is not a rare case, it is a large market of android tv applications.

@darshankawar
Copy link
Member

Hi @SebastianRuettger,
Can you please confirm if you still experience the issue on latest Stable version ?
Thanks.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 25, 2020
@SebastianRuettger
Copy link
Author

SebastianRuettger commented Aug 25, 2020 via email

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 25, 2020
@Guillaume-Fortin
Copy link

Guillaume-Fortin commented Sep 4, 2020

i have same problem with flutter 1.17.5.
i will test on 1.20.3

@Guillaume-Fortin
Copy link

I have migrate to flutter 1.20.3 and the problem still present on android.

I have a home screen and when i scan with a barcode device plugged with phone, the keyboard keep open after navigation or after dismiss a previous screen keyboard.

For resolve the problem, i need back and return to application on android with application manager.

The used device => Unitech PA760

@Guillaume-Fortin
Copy link

I debuged.
The method TextInputPlugin.getLastInputConnection keep a reference to an old lastInputConnection when the bug is produced.
When i resume application, the lastInputConnection property begin null and the keyevent work.

@pedromassangocode pedromassangocode added e: device-specific Only manifests on certain devices passed first triage labels Sep 25, 2020
@CyrilHu
Copy link

CyrilHu commented Oct 14, 2020

i have same problem with flutter 1.22.1

@nrutledge
Copy link

nrutledge commented Nov 20, 2020

I've just encountered this in Flutter 1.22.4. This is a major problem for any apps integrated with external input devices like barcode scanners.

Has anyone found a suitable workaround that can be used until this is resolved? Currently, I'm resorting to hiding the keyboard after each scan but it causes the keyboard to flash on screen each time which is jarring.

UPDATE: Originally I was testing with the Android emulator. I've just tested now with two physical devices and cannot reproduce on those as of yet.

@pkotowski
Copy link

pkotowski commented Dec 10, 2020

Same issue:
[√] Flutter (Channel stable, 1.22.4, on Microsoft Windows [Version 10.0.19041.630], locale pl-PL)

Also very important for me as POS systems manufacturer.

OnScreen keyboard is not showing until any TextField input got focus. After that, keyboard will be shown on every keyboard input, also when no TextField widgets are on current Scaffold.

@aakashbapna
Copy link

@darshankawar able to reproduce the issue on 1.22.4 on physical device.

@fredrikjacobson
Copy link

@aakashbapna Are you performing any workaround currently?
How's the experience with hiding keyboard on keypress?

@aakashbapna
Copy link

aakashbapna commented Jan 29, 2021

@fredrikjacobson no workaround except switching to beta channel to atleast get the RawKeyEvent. Hiding the keyboard is very jarring experience for the user, if I don't hide the keyboard onKey, the only way for user to dismiss keyboard is to focus a text field and then dismiss (using "done" on keyboard or un-focussing text field).

@misha
Copy link

misha commented Jun 15, 2021

I have a completely different use case. The app is a game that brings up a TextField for entering text commands, but otherwise uses all keyboard events for in-game actions.

After bringing up the TextField just once, RawKeyDownEvent stops being delivered to the RawKeyboardListener, and every press triggers the soft keyboard. As a user above mentioned, pausing and resuming the app appears to fix the state, but I have no workaround. Very, very stuck!

Flutter 2.2.0 • channel beta • https://github.com/flutter/flutter.git
Framework • revision b22742018b (5 weeks ago) • 2021-05-14 19:12:57 -0700
Engine • revision a9d88a4d18
Tools • Dart 2.13.0

@fanchou
Copy link

fanchou commented Jun 15, 2021

TextInputType.none: #83974

@red282
Copy link

red282 commented Nov 30, 2021

With some debugging, I found that the selectionChanged value is always true on pressing any key from my bluetooth keyboard.

final bool selectionChanged = _value.selection != value.selection;

For example, my printed values are following:

  • from TextSelection.collapsed(offset: 1, affinity: TextAffinity.downstream, isDirectional: false)
  • to TextSelection.collapsed(offset: 2, affinity: TextAffinity.downstream, isDirectional: false)

So, this condition is also always true.

// Changes made by the keyboard can sometimes be "out of band" for listening
// components, so always send those events, even if we didn't think it
// changed. Also, the user long pressing should always send a selection change
// as well.
if (selectionChanged ||
(userInteraction &&
(cause == SelectionChangedCause.longPress ||
cause == SelectionChangedCause.keyboard))) {
_handleSelectionChanged(_value.selection, cause);
}

And, in _handleSelectionChanged function, requestKeyboard() is called, which brings to show the on-screen keyboard.

void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) {
// We return early if the selection is not valid. This can happen when the
// text of [EditableText] is updated at the same time as the selection is
// changed by a gesture event.
if (!widget.controller.isSelectionWithinTextBounds(selection))
return;
widget.controller.selection = selection;
// This will show the keyboard for all selection changes on the
// EditableWidget, not just changes triggered by user gestures.
requestKeyboard();

I checked both master & stable branches.

Is it a normal behavior that the selection change is evaluated always as true with an external keyboard? (I have not overall understanding for logics around those codes.)

@red282
Copy link

red282 commented Dec 1, 2021

Above issue is ocurred only with Samsung keyboard.
Not reproduced with Gboard.

@gomcodoctor
Copy link

I am facing same issue with Gboard !

@goderbauer goderbauer added the P3 Issues that are less important to the Flutter project label Sep 27, 2022
@flutter-triage-bot flutter-triage-bot bot added team-framework Owned by Framework team triaged-framework Triaged by Framework team labels Jul 8, 2023
@rekire
Copy link

rekire commented Sep 16, 2023

Related Android Bug: https://issuetracker.google.com/issues/300236999

@karatekid430
Copy link

It's 2024 and they have not fixed a simple bug which clearly is affecting a people in a serious way.

@bleroux
Copy link
Contributor

bleroux commented Jan 29, 2024

Closing because this is fixed on master, see flutter/engine#49829.

Before this fix, the IME internal state was reset when a text field is focused but not when it was unfocused. Depending on the IME this results on the IME still reacting based on the configuration of the last focused text field.
With this fix, the IME internal state is reset when a text field is unfocused.

@bleroux bleroux closed this as completed Jan 29, 2024
@bleroux bleroux added the r: fixed Issue is closed as already fixed in a newer version label Jan 29, 2024
Copy link

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 Feb 12, 2024
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 e: device-specific Only manifests on certain devices framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project r: fixed Issue is closed as already fixed in a newer version team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
Status: Done (PR merged)
Development

Successfully merging a pull request may close this issue.