handlePointerEventRecord method

  1. @override
Future<List<Duration>> handlePointerEventRecord(
  1. 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.

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.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;
  });
}