Comments (4)
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:
- calling
simulateKeyUpEvent
before simulating another press. - relying on
tester.sendKeyEvent
which simulates a down event followed by an up event.
Thanks for trying these.
from flutter.
but there is still issue with tester.sendKeyEvent Please try the below test
This is because tester.sendKeyEvent
should be 'awaited',
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);
});
}
from flutter.
Oops! looks like I am not fully awake yet 😄
Closing as working as intended.
Thank you.
from flutter.
Hi @bleroux,
Thanks for the fix, I tried both the ways simulateKeyUpEvent
seems to work
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 tester.sendKeyEvent
Please try the below test
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);
});
}
from flutter.
Related Issues (20)
- Flutter doctor does not evaluate the same version of java that is used when building HOT 2
- Investigate `const`ness HOT 3
- RFW golden-file test is/was blocking engine->framework roll HOT 2
- The SearchDelegate does not use the AppBarTheme of the current theme HOT 2
- [Impeller] ListView in CupertinoPageScaffold becomes unresponsive in Simulator. HOT 7
- I can't get flutter to work HOT 1
- Size difference between Impeller blur and legacy (Skia) blur HOT 4
- Error occurs on real device when taking screenshot HOT 9
- [camerax] Level 1 Android devices can't do image analysis and image capture at the same time HOT 1
- [New Feature]Click on the widget to jump to the corresponding line of code in the IDE HOT 3
- GoRouter - Location cannot be empty. HOT 10
- [tool_crash] FileSystemException: Creation failed, OS Error: The system cannot find the file specified., errno = 2 HOT 1
- Sometimes the ColorScheme generated by ColorScheme.fromSeed has the same color for different color role HOT 2
- Error starting debug session in Xcode: Timed out waiting for CONFIGURATION_BUILD_DIR to update HOT 1
- Pigeon throws `TypeError` with `copyrightHeader` in `kotlinOptions` HOT 5
- MouseRegion for Touchscreens HOT 3
- [Method Channel][ActivityAware] global variable activity is null when it call in setmethodhandler and app is running in background HOT 1
- [image_picker] maxWidth and maxHeight setting do not work with images taken from a device camera in Portrait orientation HOT 1
- Failed build for Web app with Flutter 3.22.2 HOT 2
- [Android] Upgrading to minSdk 23, makes app size 2 times bigger with flutter build apk HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.