memoryEvents function

Future<List<ObjectEvent>> memoryEvents(
  1. FutureOr<void> callback(),
  2. Type type
)

Invokes callback and collects events dispatched to FlutterMemoryAllocations.instance for type.

Implementation

Future<List<ObjectEvent>> memoryEvents(
  FutureOr<void> Function() callback,
  Type type,
) async {
  final events = <ObjectEvent>[];

  void listener(ObjectEvent event) {
    if (event.object.runtimeType == type) {
      events.add(event);
    }
  }

  FlutterMemoryAllocations.instance.addListener(listener);
  await callback();
  FlutterMemoryAllocations.instance.removeListener(listener);

  return events;
}