每个动画帧会回调一次。
-
创建时,ticker的初始状态是禁用的。调用[start]启动。
-
A [Ticker]可以通过将[muted]设置为true来进行沉默。在沉默状态下,时间仍然在流逝,[start]和[stop]仍然可以被调用,但是不会回调到Ticker中。
-
按照约定,[start]和[stop]方法由[ticker]的使用者使用,[muted]属性由[TickerProvider] 控制。
-
Ticker回调是由[SchedulerBinding]驱动的。[SchedulerBinding.scheduleFrameCallback]。
**总结: **每次frame绘制之前会回调到ticker,由SchedulerBinding进行驱动
ScheduleBinding
/// Scheduler for running the following:
///
/// * Transient callbacks, triggered by the system’s [Window.onBeginFrame]
/// callback, for synchronizing the application’s behavior to the system’s
/// display. For example, [Ticker]s and [AnimationController]s trigger from
/// these.
///
/// * Persistent callbacks, triggered by the system’s [Window.onDrawFrame]
/// callback, for updating the system’s display after transient callbacks have
/// executed. For example, the rendering layer uses this to drive its
/// rendering pipeline.
///
/// * Post-frame callbacks, which are run after persistent callbacks, just
/// before returning from the [Window.onDrawFrame] callback.
///
/// * Non-rendering tasks, to be run between frames. These are given a
/// priority and are executed in priority order according to a
/// [schedulingStrategy].
调度运行时的这些回调
-
Transient callbacks,由系统的[Window.onBeginFrame]回调,用于同步应用程序的行为到系统的展示。例如,[Ticker]s和[AnimationController]s触发器来自与它。
-
Persistent callbacks 由系统的[Window.onDrawFrame]方法触发回调,用于在TransientCallback执行后更新系统的展示。例如,渲染层使用他来驱动渲染管道进行build,layout,paint
-
_Post-frame callbacks_在下一帧绘制前回调,主要做一些清理和准备工作
-
Non-rendering tasks 非渲染的任务,在帧构造之间,他们具有优先级,通过[schedulingStrategy]的优先级进行执行,例如用户的输入
**总结:**FrameCallback:SchedulerBinding 类中有三个FrameCallback回调队列, 在一次绘制过程中,这三个回调队列会放在不同时机被执行:
-
transientCallbacks:用于存放一些临时回调,一般存放动画回调。可以通过
SchedulerBinding.instance.scheduleFrameCallback
添加回调。 -
persistentCallbacks:用于存放一些持久的回调,不能在此类回调中再请求新的绘制帧,持久回调一经注册则不能移除。
SchedulerBinding.instance.addPersitentFrameCallback()
,这个回调中处理了布局与绘制工作。 -
postFrameCallbacks:在Frame结束时只会被调用一次,调用后会被系统移除,可由
SchedulerBinding.instance.addPostFrameCallback()
注册,注意,不要在此类回调中再触发新的Frame,这可以会导致循环刷新。
/// 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 a one-off registration, ignore the rescheduling
a