onReportTimings property Null safety

TimingsCallback? onReportTimings
override

A callback that is invoked to report the FrameTiming of recently rasterized frames.

Accessing this value returns the value contained in the PlatformDispatcher singleton, so instead of getting it from here, you should consider getting it from WidgetsBinding.instance.platformDispatcher instead (or, when WidgetsBinding isn't available, from PlatformDispatcher.instance). The reason this value forwards to the PlatformDispatcher is to provide convenience for applications that only use a single main window.

It's preferred to use SchedulerBinding.addTimingsCallback than to use SingletonFlutterWindow.onReportTimings directly because SchedulerBinding.addTimingsCallback allows multiple callbacks.

This can be used to see if the window has missed frames (through FrameTiming.buildDuration and FrameTiming.rasterDuration), or high latencies (through FrameTiming.totalSpan).

Unlike Timeline, the timing information here is available in the release mode (additional to the profile and the debug mode). Hence this can be used to monitor the application's performance in the wild.

The callback takes a list of FrameTiming because it may not be immediately triggered after each frame. Instead, Flutter tries to batch frames together and send all their timings at once to decrease the overhead (as this is available in the release mode). The list is sorted in ascending order of time (earliest frame first). The timing of any frame will be sent within about 1 second (100ms if in the profile/debug mode) even if there are no later frames to batch. The timing of the first frame will be sent immediately without batching.

If this is null, no additional work will be done. If this is not null, Flutter spends less than 0.1ms every 1 second to report the timings (measured on iPhone6S). The 0.1ms is about 0.6% of 16ms (frame budget for 60fps), or 0.01% CPU usage per second.

Implementation

@override
ui.TimingsCallback? get onReportTimings => platformDispatcher.onReportTimings;
void onReportTimings=(TimingsCallback? callback)
override

Implementation

@override
set onReportTimings(ui.TimingsCallback? callback) {
  platformDispatcher.onReportTimings = callback;
}