In case you need timed zoom, I wrote extension with timedZoomFrom
method, similar to timedDragFrom
of WidgetController
.
extension ZoomTesting on WidgetTester{
Future<void> timedZoomFrom(
Offset startLocation1,
Offset offset1,
Offset startLocation2,
Offset offset2,
Duration duration, {
int? pointer,
int buttons = kPrimaryButton,
double frequency = 60.0,
}) {
assert(frequency > 0);
final int intervals = duration.inMicroseconds * frequency ~/ 1E6;
assert(intervals > 1);
pointer ??= nextPointer;
int pointer2 = pointer + 1;
final List<Duration> timeStamps = <Duration>[
for (int t = 0; t <= intervals; t += 1)
duration * t ~/ intervals,
];
final List<Offset> offsets1 = <Offset>[
startLocation1,
for (int t = 0; t <= intervals; t += 1)
startLocation1 + offset1 * (t / intervals),
];
final List<Offset> offsets2 = <Offset>[
startLocation2,
for (int t = 0; t <= intervals; t += 1)
startLocation2 + offset2 * (t / intervals),
];
final List<PointerEventRecord> records = <PointerEventRecord>[
PointerEventRecord(Duration.zero, <PointerEvent>[
PointerAddedEvent(
position: startLocation1,
),
PointerAddedEvent(
position: startLocation2,
),
PointerDownEvent(
position: startLocation1,
pointer: pointer,
buttons: buttons,
),
PointerDownEvent(
position: startLocation2,
pointer: pointer2,
buttons: buttons,
),
]),
...<PointerEventRecord>[
for(int t = 0; t <= intervals; t += 1)
PointerEventRecord(timeStamps[t], <PointerEvent>[
PointerMoveEvent(
timeStamp: timeStamps[t],
position: offsets1[t+1],
delta: offsets1[t+1] - offsets1[t],
pointer: pointer,
buttons: buttons,
),
PointerMoveEvent(
timeStamp: timeStamps[t],
position: offsets2[t+1],
delta: offsets2[t+1] - offsets2[t],
pointer: pointer2,
buttons: buttons,
),
]),
],
PointerEventRecord(duration, <PointerEvent>[
PointerUpEvent(
timeStamp: duration,
position: offsets1.last,
pointer: pointer,
),
PointerUpEvent(
timeStamp: duration,
position: offsets2.last,
pointer: pointer2,
),
]),
];
return TestAsyncUtils.guard<void>(() async {
await handlePointerEventRecord(records);
});
}
}
Using example:
// fast zoom in
await tester.timedZoomFrom(
center.translate(-10, 0), const Offset(-100, 0),
center.translate(10, 0), const Offset(100, 0),
const Duration(seconds: 1));