handlePointerEventRecord method Null safety
- Iterable<
PointerEventRecord> records
override
A simulator of how the framework handles a series of PointerEvents received from the Flutter engine.
The PointerEventRecord.timeDelay is used as the time delay of the events injection relative to the starting point of the method call.
Returns a list of the difference between the real delay time when the PointerEventRecord.events are processed and PointerEventRecord.timeDelay.
- For AutomatedTestWidgetsFlutterBinding where the clock is fake, the return value should be exact zeros.
- For LiveTestWidgetsFlutterBinding, the values are typically small positives, meaning the event happens a little later than the set time, but a very small portion may have a tiny negative value for about tens of microseconds. This is due to the nature of Future.delayed.
The closer the return values are to zero the more faithful it is to the
records
.
See PointerEventRecord.
Implementation
@override
Future<List<Duration>> handlePointerEventRecord(Iterable<PointerEventRecord> records) {
assert(records != null);
assert(records.isNotEmpty);
return TestAsyncUtils.guard<List<Duration>>(() async {
final List<Duration> handleTimeStampDiff = <Duration>[];
DateTime? startTime;
for (final PointerEventRecord record in records) {
final DateTime now = binding.clock.now();
startTime ??= now;
// So that the first event is promised to receive a zero timeDiff
final Duration timeDiff = record.timeDelay - now.difference(startTime);
if (timeDiff.isNegative) {
// Flush all past events
handleTimeStampDiff.add(-timeDiff);
for (final PointerEvent event in record.events) {
binding.handlePointerEventForSource(event, source: TestBindingEventSource.test);
}
} else {
await binding.pump();
await binding.delayed(timeDiff);
handleTimeStampDiff.add(
binding.clock.now().difference(startTime) - record.timeDelay,
);
for (final PointerEvent event in record.events) {
binding.handlePointerEventForSource(event, source: TestBindingEventSource.test);
}
}
}
await binding.pump();
// This makes sure that a gesture is completed, with no more pointers
// active.
return handleTimeStampDiff;
});
}