Skip to content

RawKeyboardListener triggers soft keyboard on Android #70546

Closed
flutter-team-archive/engine
#49829

Description

@pascalw

This was spun off from #67915.

On Android, RawKeyboardListener triggers the soft keyboard when it receives input. This only happens after a TextField has received focus once. Until a TextField has received focus, the soft keyboard remains hidden.

Steps to Reproduce

  1. Run flutter create bug.
  2. Replace main.dart with this:
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final FocusNode rawKbFocusNode = FocusNode();
  final FocusNode textFocusNode = FocusNode();

  bool renderTextField = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RawKeyboardListener(
              onKey: (event) {
                print(event);
              },
              focusNode: rawKbFocusNode,
              autofocus: true,
              child: renderTextField
                  ? TextField(
                      focusNode: textFocusNode,
                    )
                  : Text('No textfield'),
            ),
            RaisedButton(
              child: Text('Focus RawKeyboardListener'),
              onPressed: () => rawKbFocusNode.requestFocus(),
            ),
            RaisedButton(
              child: Text('Toggle textfield'),
              onPressed: () => setState(() {
                renderTextField = !renderTextField;
              }),
            )
          ],
        ),
      ),
    );
  }
}
  1. Use a hardware keyboard to enter text. Key events are printed, no soft keyboard is visible.
  2. Focus the text field. Move focus back to RawKeyboardListener.
  3. Use the hardware keyboard again to enter text. Now the soft keyboard will pop up.
  4. Dismiss the soft keyboard and enter some more text. Soft keyboard will show again.
  5. Even if the TextField is not rendered anymore, the same behavior keeps happening.

Expected results:

I expected the soft keyboard to remain hidden. As long as noTextField receives focus, things behave as expected.
Only after a TextField has received focus once, the soft keyboard will keep popping up when the RawKeyboardListener receives input.

Actual results:

The soft keyboard shows up.

Here's a gif showing the behavior.
All input is typed via a hardware keyboard.

rawkeyboardlistener

flutter doctor -v
[✓] Flutter (Channel master, 1.24.0-8.0.pre.230, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-GB)
    • Flutter version 1.24.0-8.0.pre.230 at /Users/Pascal/.local/flutter-master
    • Framework revision af5eb3b987 (32 hours ago), 2020-11-13 19:57:15 +0800
    • Engine revision dddb532b5c
    • Dart version 2.12.0 (build 2.12.0-37.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at /Users/Pascal/Library/Android/sdk
    • Platform android-30, build-tools 30.0.1
    • ANDROID_HOME = /Users/Pascal/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • CocoaPods version 1.9.3

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Community Edition (version 2019.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.51.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (2 available)
    • sdk gphone x86 64 (mobile) • emulator-5554 • android-x64 • Android 11 (API 30) (emulator)
    • macOS (desktop)            • macos         • darwin-x64  • Mac OS X 10.15.7 19H15 darwin-x64

• No issues found!

Activity

  1. pedromassangocode commented on Nov 16, 2020

    @pedromassangocode

    Hi @pascalw
    I cannot reproduce the issue on latest master channel.
    gif

    flutter doctor -v
    [✓] Flutter (Channel master, 1.24.0-8.0.pre.252, on Mac OS X 10.15.7 19H2 darwin-x64, locale en)
        • Flutter version 1.24.0-8.0.pre.252 at /Users/pedromassango/dev/SDKs/flutter_master
        • Framework revision bf2c9dfc05 (33 hours ago), 2020-11-14 22:38:02 -0500
        • Engine revision 3e77d854a7
        • Dart version 2.12.0 (build 2.12.0-45.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/pedromassango/Library/Android/sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.1, Build version 12A7403
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    
    [✓] IntelliJ IDEA Community Edition (version 2020.2.3)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 51.0.3
        • Dart plugin version 202.8070
    
    [✓] VS Code (version 1.51.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.16.0
    
    [✓] Connected device (4 available)
        • Pixel 3 (mobile) • 192.168.56.102:5555 • android-x86    • Android 9 (API 28)
        • macOS (desktop)  • macos               • darwin-x64     • Mac OS X 10.15.7 19H2 darwin-x64
        • Web Server (web) • web-server          • web-javascript • Flutter Tools
        • Chrome (web)     • chrome              • web-javascript • Google Chrome 86.0.4240.193
    
    • No issues found!
    
    
  2. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 16, 2020
  3. pascalw commented on Nov 16, 2020

    @pascalw
    Author

    @pedromassangocode I just tried it again on 1.24.0-8.0.pre.252 and it still reproduces for me.
    Are you sure your emulator is configured with actual hardware keyboard support and not Genymotion relaying keyboard strokes from the host to the emulator in some way?

    For me this issue is reproducible on the emulator (Android 11), configured with hardware keyboard support. In practice I'm running into this issue on a Honeywell CT60 which has a hardware barcode scanner that can relay scanned barcodes as keyboard strokes. It exhibits the same behavior, also on current master.

    @amitozalvo you reported similar behavior in the other issue about RawkeyboardListener. Can you perhaps confirm this snippet here reproduces the issue for you too?

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 16, 2020
  5. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: focusFocus traversal, gaining or losing focus
    on Nov 16, 2020
  6. pedromassangocode commented on Nov 17, 2020

    @pedromassangocode

    Yes somehow Genymotion was not handling the physical keyboard correctly. I was able to reproduce with a native Android emulator.

    gif

    flutter doctor -v
    [✓] Flutter (Channel master, 1.24.0-8.0.pre.267, on Mac OS X 10.15.7 19H2
        darwin-x64, locale en)
        • Flutter version 1.24.0-8.0.pre.267 at
          /Users/pedromassango/dev/SDKs/flutter_master
        • Framework revision 22e576fa26 (8 hours ago), 2020-11-16 18:48:03 -0500
        • Engine revision f0e80100f7
        • Dart version 2.12.0 (build 2.12.0-49.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/pedromassango/Library/Android/sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: /Applications/Android
          Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6915495)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.1, Build version 12A7403
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6915495)
    
    [✓] IntelliJ IDEA Community Edition (version 2020.2.3)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 51.0.3
        • Dart plugin version 202.8070
    
    [✓] VS Code (version 1.51.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.16.0
    
    [✓] Connected device (4 available)
        • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86    • Android 11
          (API 30) (emulator)
        • macOS (desktop)             • macos         • darwin-x64     • Mac OS X
          10.15.7 19H2 darwin-x64
        • Web Server (web)            • web-server    • web-javascript • Flutter
          Tools
        • Chrome (web)                • chrome        • web-javascript • Google
          Chrome 86.0.4240.198
    
    • No issues found!
    
  7. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Nov 17, 2020
  8. added
    engineflutter/engine related. See also e: labels.
    on Nov 18, 2020
  9. nrutledge commented on Nov 20, 2020

    @nrutledge

    This appears to be the same issue as #51478

  10. added
    P2Important issues not at the top of the work list
    on Dec 11, 2020
  11. 70 remaining items

  12. removed
    r: fixedIssue is closed as already fixed in a newer version
    on Sep 2, 2024
  13. moved this from In progress to To do in Nevercodeon Nov 18, 2024
  14. github-actions commented on Aug 8, 2025

    @github-actions

    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.

  15. locked as resolved and limited conversation to collaborators on Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.f: focusFocus traversal, gaining or losing focusfound in release: 3.16Found to occur in 3.16found in release: 3.19Found to occur in 3.19frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions