playEvent method
Future<FlutsterTestEvent?>
playEvent(
- FlutsterTestEvent flutsterTestEvent, {
- Duration delay = const Duration(milliseconds: 0),
- WidgetTester? tester,
playEvent plays the given event on the child widget.
Implementation
Future<FlutsterTestEvent?> playEvent(
FlutsterTestEvent flutsterTestEvent, {
Duration delay = const Duration(milliseconds: 0),
WidgetTester? tester,
}) async {
switch (flutsterTestEvent.type) {
case FlutsterTestEventType.screenShot:
FlutsterTestEvent? ret;
if (tester != null) {
await tester.pumpAndSettle();
}
await Future.delayed(delay).whenComplete(() async {
ret = await returnScreenShotEvent(
duplicate: flutsterTestEvent, tester: tester);
});
return (ret);
case FlutsterTestEventType.tap:
WidgetController? controller;
if (tester == null) {
controller = LiveWidgetController(WidgetsBinding.instance);
} else {
controller = tester;
}
if (flutsterTestEvent.tapDuration == null ||
flutsterTestEvent.tapStop == null) {
await Future.delayed(delay).whenComplete(() async {
await controller!.tapAt(
flutsterTestEvent.tapStart!,
);
});
} else {
await Future.delayed(delay).whenComplete(() async {
TestGesture gesture = await controller!.startGesture(
flutsterTestEvent.tapStart!,
kind: PointerDeviceKind.touch,
);
await gesture.moveTo(flutsterTestEvent.tapStop!,
timeStamp: flutsterTestEvent.tapDuration!);
await gesture.up();
await controller.pump();
});
}
return (flutsterTestEvent);
case FlutsterTestEventType.key:
if (tester == null) {
snack(const Text("Cannot replay key events in a non test situation"));
return (null);
}
FlutsterTestEvent? ret = flutsterTestEvent;
await Future.delayed(delay).whenComplete(() async {
bool keyDown = false;
if (flutsterTestEvent.keyEvent is KeyDownEvent ||
flutsterTestEvent.keyEvent is RawKeyDownEvent ||
(flutsterTestEvent.keyEventDown ?? false)) {
keyDown = true;
}
if (flutsterTestEvent.typedText?.isEmpty ?? true) {
if (keyDown) {
if (!await tester
.sendKeyDownEvent(flutsterTestEvent.keyEvent!.logicalKey)) {
ret = null;
}
} else {
if (!await tester.sendKeyUpEvent(
flutsterTestEvent.keyEvent!.logicalKey,
)) {
debugPrint(
"send key up returned false, not stopping the test run for "
"that");
}
await tester.pumpAndSettle();
}
} else {
tester.testTextInput.enterText(flutsterTestEvent.typedText ?? "");
await tester.pumpAndSettle();
}
});
return (ret);
default:
return (null);
}
}