Repository navigation
RawKeyboardListener triggers soft keyboard on Android #70546
Copy link
Copy link
Closed
flutter-team-archive/engine
#49829Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.f: focusFocus traversal, gaining or losing focusFocus traversal, gaining or losing focusfound in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.19Found to occur in 3.19Found to occur in 3.19frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Description
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
- Run
flutter create bug. - Replace
main.dartwith 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;
}),
)
],
),
),
);
}
}- Use a hardware keyboard to enter text. Key events are printed, no soft keyboard is visible.
- Focus the text field. Move focus back to
RawKeyboardListener. - Use the hardware keyboard again to enter text. Now the soft keyboard will pop up.
- Dismiss the soft keyboard and enter some more text. Soft keyboard will show again.
- 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.
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!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.f: focusFocus traversal, gaining or losing focusFocus traversal, gaining or losing focusfound in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.19Found to occur in 3.19Found to occur in 3.19frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team

Activity
pedromassangocode commentedon Nov 16, 2020
Hi @pascalw

I cannot reproduce the issue on latest master channel.
flutter doctor -v
pascalw commentedon Nov 16, 2020
@pedromassangocode I just tried it again on
1.24.0-8.0.pre.252and 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?pedromassangocode commentedon Nov 17, 2020
Yes somehow Genymotion was not handling the physical keyboard correctly. I was able to reproduce with a native Android emulator.
flutter doctor -v
nrutledge commentedon Nov 20, 2020
This appears to be the same issue as #51478
70 remaining items
[Android] Revert "Reset IME state on clear text input client" (flutte…
Fix previous text input connection interrupts enter/space (#171973)
Fix previous text input connection interrupts enter/space (flutter#17…
github-actions commentedon Aug 8, 2025
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 -vand a minimal reproduction of the issue.Fix previous text input connection interrupts enter/space (flutter#17…
Fix previous text input connection interrupts enter/space (flutter#17…
Fix previous text input connection interrupts enter/space (flutter#17…
Fix previous text input connection interrupts enter/space (flutter#17…
Fix previous text input connection interrupts enter/space (#171973)
[Android] Reset IME state in TextInputPlugin.clearTextInputClient (fl…