Closed Xazin closed 2 weeks ago
@Xazin Thanks for the report.
The widget RawKeyboardListener
you are using listens to the key events only when its focus node has focus.
Also, I observed that this widget / api is now deprecated, per:
So, can you try KeyboardListener
instead of it and check if you still get same behavior or not ?
https://api.flutter.dev/flutter/widgets/KeyboardListener-class.html
@Xazin Thanks for the report.
The widget
RawKeyboardListener
you are using listens to the key events only when its focus node has focus.Also, I observed that this widget / api is now deprecated, per:
So, can you try
KeyboardListener
instead of it and check if you still get same behavior or not ?https://api.flutter.dev/flutter/widgets/KeyboardListener-class.html
I already tried KeyboardListener, and it didn't change the result. This was my first idea as well, I just reported using RawKeyboardListener as that is what we primarily use in our applications (which I will make sure to replace), as we often need to check for modifiers such as if shift is also pressed.
There is no issue on stable, which suggests something broke somewhere.
Our application (AppFlowy) is heavily reliant on text editing, our own implementations of editable text does not break, but all common usage of TextFields does break throughout the app.
Thanks for the update. I was able to replicate the reported behavior on desktop only (tried on macos), while on web and mobile, it works as expected. The reported behavior occurs on latest beta and master, while on stable, it works as expected. Below are the exact steps to replicate the behavior.
flutter run -d macos
:this is test
).Change
button.Change
button again and append any text and hit escape (without saving), which will close the dialog.Change
button again and try to delete the existing text or hit escape button which again doesn't perform any action.Adding regression
label, since it works on latest stable, but not on latest master and beta.
/cc @justinmc @gspencergoog
I can also reproduce this, I'll try and bisect it to the offending change.
In the meantime, there is a workaround: use Shortcuts
instead, which doesn't seem to have this problem.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const Home(),
theme: ThemeData.light(useMaterial3: true),
);
}
}
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
String val = 'Hello World';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('TextField breaks')),
body: Column(
children: <Widget>[
Text('Value: $val'),
TextButton(
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => ADialog(
value: val,
),
).then((String? v) {
if (mounted && v != null && v != val) {
setState(() => val = v);
}
}),
child: const Text('Change'),
),
const TextField(),
],
),
);
}
}
class ADialog extends StatefulWidget {
const ADialog({super.key, required this.value});
final String value;
@override
State<ADialog> createState() => ADialogState();
}
class ADialogState extends State<ADialog> {
final FocusNode focusNode = FocusNode();
late final TextEditingController controller = TextEditingController(text: widget.value);
@override
void dispose() {
focusNode.dispose();
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Edit text'),
content: Shortcuts(
shortcuts: <ShortcutActivator, Intent>{
const SingleActivator(LogicalKeyboardKey.escape): VoidCallbackIntent(() {
Navigator.of(context).pop();
}),
},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextField(
controller: controller,
autofocus: true,
),
TextButton(
onPressed: () => Navigator.of(context).pop(controller.text),
child: const Text('Save'),
)
],
),
),
);
}
}
@gspencergoog I bisected to https://github.com/flutter/flutter/pull/134554. Not sure why I can't repro it on Linux. I did the bisect on macOS.
Ahh, @bleroux I wish I'd seen your comment earlier. :-). I bisected to the same change, though.
@chunhtai Seems like your PR is the cause of this regression, at least on macOS. Can you take a look?
I've found the issue, thanks a lot for bisecting, luckily I saw both messages before starting.
Issue specifically stems from changes in lib/src/widgets/routes.dart
More specifically calling changedInternalState()
in
@override
void didPopNext(Route<dynamic> nextRoute) {
super.didPopNext(nextRoute);
changedInternalState();
}
Seems to stem from the call to setState
in changedInternalState
as a result of didPopNext
For some reason if the textfield in the dialog is focused and user presses esc, the FlutterTextInputPlugin receives cancelOperation selector and attempt to send to the framework but got stuck. which blocks the rest selector call to. I guess it probably has something to do with the esc was handled in the framework side or some weirdness when disposing textfield. Needs more investigation
Looks like the change somhow made the TextField in the dialog give up connection a bit faster, which should be fine and it will make FlutterTextInputPlugin to give up firstResponder. However, the FlutterTextInputPlugin some how still receive cancel operation after it gave up firstResponder. I think this is more of a corner case in FlutterTextInputPlugin that gets surfaced by my previous pr. I will send a patch to macos engine
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.
Steps to reproduce
Using a RawKeyboardListener.onKey that wraps a TextField, to close a Dialog using
Navigator.pop
.Notice: Could not be reproduced on Windows, but reproduced on multiple MacOS devices. Cannot be reproduced on
stable
, only onbeta
(both3.18
and3.19
)Expected results
TextFields can receive and act on input normally.
Actual results
All TextFields are broken and can no longer function properly, eg. backspace doesn't work.
Code sample
Code sample
```dart import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: const Home(), theme: ThemeData.light(useMaterial3: true), ); } } class Home extends StatefulWidget { const Home({super.key}); @override StateScreenshots or Video
Screenshots / Video demonstration
https://github.com/flutter/flutter/assets/42929161/a688898e-e684-4723-bf89-9dfe635d8808Logs
Nothing at all in the logs.
Flutter Doctor output
Doctor output
```console [✓] Flutter (Channel beta, 3.19.0-0.4.pre, on macOS 14.2 23C64 darwin-arm64, locale en-DK) • Flutter version 3.19.0-0.4.pre on channel beta at /Users/mathias/Development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision b7e7d46a04 (8 days ago), 2024-02-02 08:21:06 -0600 • Engine revision 98820f0a77 • Dart version 3.3.0 (build 3.3.0-279.3.beta) • DevTools version 2.31.0 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/mathias/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15C65 • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.3) • 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 17.0.6+0-17.0.6b829.9-10027231) [✓] VS Code (version 1.85.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.82.0 [✓] Connected device (4 available) • Super iPhone (mobile) • 00008110-00123CD634D9401E • ios • iOS 17.2.1 21C66 • iPhone 15 Pro (mobile) • 4DE2390A-F63A-4355-AB41-51C0E40E4913 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.2 23C64 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.160 [✓] Network resources • All expected network resources are available. • No issues found! ```