scheduleFrameCallback method
- FrameCallback callback, {
- bool rescheduling = false,
Schedules the given transient frame callback.
Adds the given callback to the list of frame callbacks and ensures that a frame is scheduled.
If this is called during the frame's animation phase (when transient frame
callbacks are still being invoked), a new frame will be scheduled, and
callback
will be called in the newly scheduled frame, not in the current
frame.
If this is a one-off registration, ignore the rescheduling
argument.
If this is a callback that will be re-registered each time it fires, then
when you re-register the callback, set the rescheduling
argument to
true. This has no effect in release builds, but in debug builds, it
ensures that the stack trace that is stored for this callback is the
original stack trace for when the callback was first registered, rather
than the stack trace for when the callback is re-registered. This makes it
easier to track down the original reason that a particular callback was
called. If rescheduling
is true, the call must be in the context of a
frame callback.
Callbacks registered with this method can be canceled using cancelFrameCallbackWithId.
See also:
- WidgetsBinding.drawFrame, which explains the phases of each frame for those apps that use Flutter widgets (and where transient frame callbacks fit into those phases).
Implementation
int scheduleFrameCallback(FrameCallback callback, { bool rescheduling = false }) {
scheduleFrame();
_nextFrameCallbackId += 1;
_transientCallbacks[_nextFrameCallbackId] = _FrameCallbackEntry(callback, rescheduling: rescheduling);
return _nextFrameCallbackId;
}