endOfFrame property

Future<void> endOfFrame

Returns a Future that completes after the frame completes.

If this is called between frames, a frame is immediately scheduled if necessary. If this is called during a frame, the Future completes after the current frame.

If the device's screen is currently turned off, this may wait a very long time, since frames are not scheduled while the device's screen is turned off.

Implementation

Future<void> get endOfFrame {
  if (_nextFrameCompleter == null) {
    if (schedulerPhase == SchedulerPhase.idle) {
      scheduleFrame();
    }
    _nextFrameCompleter = Completer<void>();
    addPostFrameCallback((Duration timeStamp) {
      _nextFrameCompleter!.complete();
      _nextFrameCompleter = null;
    }, debugLabel: 'SchedulerBinding.completeFrame');
  }
  return _nextFrameCompleter!.future;
}