Repository navigation
Closed
Labels
P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemse: device-specificOnly manifests on certain devicesfyi-androidFor the attention of Android platform teamplatform-androidAndroid applications specificallyr: solvedIssue is closed as solvedteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team
Description
Steps to reproduce
- Copy paste the code sample
- Run on chromecast
- Use remote bottom arrow to focus textfield and make keyboard appear
- Try to enter some text
Expected results
We should be able to use software keyboard and enter text like any other Android TV device.
Actual results
The keyboard appears fine, but nothing happens when you use the arrow keys to navigate through the letters on the keyboard. It looks like Flutter app is keeping focus.
Code sample
From @huycozy's answer on an abandonned similar issue #125541
Code sample
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
RawKeyboard.instance.addListener((e) {
debugPrint('${e.character} - ${e.logicalKey} - ${e.physicalKey}');
});
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
margin: const EdgeInsets.all(20),
child: const TextField(
decoration: InputDecoration.collapsed(hintText: 'Enter'),
),
),
),
),
);
}
}Screenshots or Video
From #125541
Screenshots / Video demonstration
IMG_1835.MOV
Logs
Logs
flutter run
Launching lib/main.dart on Chromecast HD in debug mode...
Running Gradle task 'assembleDebug'... 2 900ms
✓ Built build/app/outputs/flutter-apk/app-debug.apk
Syncing files to device Chromecast HD... 17ms
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
A Dart VM Service on Chromecast HD is available at: http://127.0.0.1:49716/M6LeYPH5OQM=/
D/ProfileInstaller(11202): Installing profile for com.example.bug_report
The Flutter DevTools debugger and profiler on Chromecast HD is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:49716/M6LeYPH5OQM=/
I/flutter (11202):
I/flutter (11202): null - LogicalKeyboardKey#4999d(keyId: "0x10000050c", keyLabel: "Select", debugName: "Select") - PhysicalKeyboardKey#c10a6(usbHidUsage: "0x00070077", debugName: "Select")
I/flutter (11202):
D/InputMethodManager(11202): showSoftInput() view=io.flutter.embedding.android.FlutterView{d77d02b VFE...... .F...... 0,0-1920,1080 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InputMethodManager(11202): showSoftInput() view=io.flutter.embedding.android.FlutterView{d77d02b VFE...... .F...... 0,0-1920,1080 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
I/flutter (11202): null - LogicalKeyboardKey#80d00(keyId: "0x100000301", keyLabel: "Arrow Down", debugName: "Arrow Down") - PhysicalKeyboardKey#556a0(usbHidUsage: "0x00070051", debugName: "Arrow Down")
W/InputMethodManager(11202): Ignoring onBind: cur seq=-1, given seq=116
D/InputConnectionAdaptor(11202): The input method toggled cursor monitoring on
D/InsetsController(11202): show(ime(), fromIme=true)
I/flutter (11202):
I/flutter (11202): null - LogicalKeyboardKey#857a2(keyId: "0x100000303", keyLabel: "Arrow Right", debugName: "Arrow Right") - PhysicalKeyboardKey#4fbfe(usbHidUsage: "0x0007004f", debugName: "Arrow Right")
I/flutter (11202):
I/flutter (11202): null - LogicalKeyboardKey#857a2(keyId: "0x100000303", keyLabel: "Arrow Right", debugName: "Arrow Right") - PhysicalKeyboardKey#4fbfe(usbHidUsage: "0x0007004f", debugName: "Arrow Right")
I/flutter (11202):
I/flutter (11202): null - LogicalKeyboardKey#857a2(keyId: "0x100000303", keyLabel: "Arrow Right", debugName: "Arrow Right") - PhysicalKeyboardKey#4fbfe(usbHidUsage: "0x0007004f", debugName: "Arrow Right")
I/flutter (11202):
I/flutter (11202): null - LogicalKeyboardKey#4999d(keyId: "0x10000050c", keyLabel: "Select", debugName: "Select") - PhysicalKeyboardKey#c10a6(usbHidUsage: "0x00070077", debugName: "Select")
I/flutter (11202):
I/flutter (11202): null - LogicalKeyboardKey#4999d(keyId: "0x10000050c", keyLabel: "Select", debugName: "Select") - PhysicalKeyboardKey#c10a6(usbHidUsage: "0x00070077", debugName: "Select")
I/flutter (11202):
I/flutter (11202): null - LogicalKeyboardKey#4999d(keyId: "0x10000050c", keyLabel: "Select", debugName: "Select") - PhysicalKeyboardKey#c10a6(usbHidUsage: "0x00070077", debugName: "Select")Flutter Doctor output
Doctor output
flutter doctor -v
[✓] Flutter (Channel stable, 3.24.2, on macOS 14.6.1 23G93 darwin-arm64, locale fr-FR)
• Flutter version 3.24.2 on channel stable at X
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4cf269e36d (7 days ago), 2024-09-03 14:30:00 -0700
• Engine revision a6bd3f1de1
• Dart version 3.5.2
• DevTools version 2.37.2
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/X/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/X/Library/Android/sdk
• Java binary at: /Users/X/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15F31d
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• CHROME_EXECUTABLE = /Applications/Chromium.app/Contents/MacOS/Chromium
[✓] Android Studio (version 2023.3)
• Android Studio at /Users/X/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 17.0.10+0-17.0.10b1087.21-11572160)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.1.1)
• IntelliJ at /Users/X/Applications/IntelliJ IDEA Ultimate.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.93.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.96.0
[✓] Connected device (6 available)
• Chromecast HD (mobile) • 192.168.1.33:5555 • android-arm • Android 12 (API 31)
[✓] Network resources
• All expected network resources are available.
• No issues found!Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemse: device-specificOnly manifests on certain devicesfyi-androidFor the attention of Android platform teamplatform-androidAndroid applications specificallyr: solvedIssue is closed as solvedteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team
Activity
darshankawar commentedon Sep 11, 2024
@romaingyh
Can you check if your issue is same as #147772 or not ?
romaingyh commentedon Sep 11, 2024
@darshankawar I don't think so, I faced the #147772 previously but you can play with focus and keyEvent around textfield as a workaround.
Another point regarding my issue : When the soft keyboard is shown, when you press return it closes the app. It really looks like the app acts as the keyboard is not visible.
darshankawar commentedon Sep 12, 2024
Thanks for the update. We currently don't have chromecast device to verify / replicate this, but based on the report and behavior occuring, keeping the issue open for team's tracking.
LongCatIsLooong commentedon Sep 12, 2024
The DefaultTextEditingShortcuts widget could be intercepting the arrow key key events so the on screen keyboard couldn't receive them.
@romaingyh Could you try overriding the default shortcuts and remap them to DoNothingAndStopPropagationIntent and see if that fixes the issue for you?
2 remaining items
romaingyh commentedon Sep 13, 2024
After experiments it seems shortcuts are not the problem. Here is the updated code :
Code sample
Behaviors are the same with or without the
Shortcutsoverride.However I found something interesting. The software keyboard works after hot restart. Here is how to reproduce :
Run the app (I run it on chromecast with
adb connect ...,flutter runUse any arrow to focus the
TextFieldand show the keyboard. Here you're in the bug and nothing happens when you press arrows to navigate in the keyboard.Hot restart the app and wait for full hot restart complete. Caret in
TextFieldshould be blinking again and keyboard still up.Now you can navigate on keyboard letters and enter some text. If you press return the keyboard closes and you're back to 2.
I made some debug prints in
editable_text.dartin methods like_openInputConnection,_openOrCloseInputConnectionIfNeededor_handleFocusChangedto compare outputs beween Android TV without the bug and Chromecast with the bug but they look the same :Any Android TV (soft. keyboard working)
Chromecast (soft. keyboard not working)
If you have any clues or guidance I would be very happy to make a PR :)
LongCatIsLooong commentedon Sep 13, 2024
I looked at the closed issue it seems the theory was that the Flutter activity has the focus over the on-screen keyboard. What is the
AppLifecycleState(You can use https://main-api.flutter.dev/flutter/widgets/AppLifecycleListener-class.html to monitor that) when you try to type using the software keyboard?Also I suspect this is because the
InputConnectionAdaptorclass is trying to handle those events instead of returning false and letting the event propagate:https://github.com/flutter/engine/blob/715ede5967c8f8be259d5832da7416a316ea927f/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java#L289-L326
which is called here: https://github.com/flutter/engine/blob/715ede5967c8f8be259d5832da7416a316ea927f/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java#L595
The android team may have more insights into this.
romaingyh commentedon Sep 15, 2024
AppLifecycleStateisresumedboth Chromecast device and normal AndroidTV device. I'm currently trying to edit the engine to makehandleKeyEventofInputConnectionAdaptor.javareturn false and see what happens. First time working on the engine I need to setup few things before.reidbaker commentedon Sep 19, 2024
From Triage: I am following up with @LongCatIsLooong out of band to see how the android team can help.
LongCatIsLooong commentedon Sep 19, 2024
@romaingyh my suspicion is that
handleHorizontalMovementet.al return true in response to arrow key events, so the system thinks the key events were consumed by the text field. If you modify thehandleKeyEventimplementation to always return false, would that allow the arrow key events to be forwarded to the software keyboard? Instructions of making such changes can be found here.romaingyh commentedon Sep 19, 2024
@LongCatIsLooong I made these changes in
InputConnectionAdaptor:But result is the same software keyboard is still not working. However I noticed that all key event if my first log are
action.ACTION_UPso we never enter in the first if block.I replaced
ACTION_DOWNwithACTION_UPto debug, now we enter in if blocks, return false when arrow pressed, but keyboard still lockedLongCatIsLooong commentedon Sep 24, 2024
So only key up events can reach this method? Maybe that's because the framework (the text field) is stealing all the down events? Could you try these shortcuts again and see if you get any down events in
handleKeyEvent?reidbaker commentedon Sep 24, 2024
@romaingyh is this the device you are targeting? https://store.google.com/config/chromecast_google_tv?hl=en-US&pli=1&selections=eyJwcm9kdWN0RmFtaWx5IjoiWTJoeWIyMWxZMkZ6ZEY5bmIyOW5iR1ZmZEhZPSJ9
reidbaker commentedon Sep 24, 2024
@LongCatIsLooong and I were able to reproduce this issue using a "TV" emulator but in our investigation we found that flutter is behaving the same as youtube and the android setting app. The text input takes the directional input just like a physical keyboard would in that it moves the cursor.
reidbaker commentedon Sep 24, 2024
Our current belief is that android TV's are moving away from dpad navigation of a soft keyboard, at least in the emulated and physical devices we had on hand. The issue we see with a flutter app running the example code also appears in native android apps.
Finally android tv is not one of our officially supported targets (aka a platform with funding and devices as part of our test lab) so it is unlikely @LongCatIsLooong or I will spend more time on this issue. I personally care about tv support because I shipped flutters apps to android tv in a past job but it only gets passion project time from me.
Closing as WAI barring other evidence and reproduction steps. We are not opposed to a pull request that fixes this issue if it gets reopened with a more specific error.
github-actions commentedon Oct 9, 2024
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.