-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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_test] A KeyDownEvent is dispatched, but the state shows that the physical key is already pressed #148986
Comments
Hey @maheshmnj! The test above simulates several key down events on the same key, this is why it triggers an error (previously, with version 3.19, the error was not thrown due to a bug). There are two ways to fix this test:
Thanks for trying these. |
Hi @bleroux, Thanks for the fix, I tried both the ways import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('simulate consecutive key down', (tester) async {
await tester.pumpWidget(const SizedBox());
await simulateKeyDownEvent(LogicalKeyboardKey.arrowDown);
await simulateKeyUpEvent(LogicalKeyboardKey.arrowDown);
await simulateKeyDownEvent(LogicalKeyboardKey.arrowDown);
await simulateKeyUpEvent(LogicalKeyboardKey.arrowDown);
await simulateKeyDownEvent(LogicalKeyboardKey.arrowDown);
await simulateKeyUpEvent(LogicalKeyboardKey.arrowDown);
await simulateKeyDownEvent(LogicalKeyboardKey.enter);
await simulateKeyUpEvent(LogicalKeyboardKey.enter);
});
} but there is still issue with import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('simulate consecutive key down', (tester) async {
await tester.pumpWidget(const SizedBox());
tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
tester.sendKeyEvent(LogicalKeyboardKey.enter);
});
} |
This is because import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('simulate consecutive key down', (tester) async {
await tester.pumpWidget(const SizedBox());
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
});
}
|
Oops! looks like I am not fully awake yet 😄 Thank you. |
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 |
Steps to reproduce
test/flutter_test.dart
flutter test test/flutter_test.dart
The test is failing when you simulate multiple
simulateKeyDownEvent
as per my understanding this used to work in flutter 3.19 (not exactly sure about the version) and belowNote: If you only have only one
simulateKeyDownEvent
the test will pass.Expected results
The test should pass without any exception
Actual results
The test fails with exception
Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: