LifecycleDispatcher class
生命周期分发核心实现类
-
继承 StateDelegate 接口,监听 State 对应的生命中周期 * widget 生命周期 initState:在整个生命周期中的初始化阶段调用,只会调用一次 didChangeDependencies:当 State 对象依赖发生变动时调用 didUpdateWidget:当 Widget 状态发生改变时调用;实际上每次更新状态时,Flutter 会创建一个新的 Widget,并在该函数中进行新旧 Widget 对比;一般调用该方法之后会调用 build reassemble:只有在 debug 或 热重载 时调用 deactivate:从 Widget Tree 中移除 State 对象时会调用,一般用在 dispose 之前 dispose:用于 Widget 被销毁时,通常会在此方法中移除监听或清理数据等,整个生命周期只会执行一次
-
混入 LifecycleOwner 提供 lifecycle 实现接口 *
-
混入 WidgetsBindingObserver 监听 App 生命周期改变,前后台切换监听 * AppLifecycleState resumed:应用程序可见且获取焦点状态,回到用户视野 inactive:应用程序处于非活动状态,可见但是不可交互的状态 paused:应用程序处于用户不可见,不响应用户状态,处于后台运行状态
-
混入 RouteAware 监听页面 进栈/出栈 相关的监听 * RouteAware didPopNext():调用时期:顶部路由弹出,当前路由显示 didPushNext():调用时期:新的路由添加入栈,当前路由不再可见
- Inheritance
-
- Object
- LifecycleDelegate
- LifecycleDispatcher
- Mixed in types
Constructors
-
LifecycleDispatcher(LifecycleOwner _owner, State<
StatefulWidget> _state)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
deactivate(
) → void -
从 Widget Tree 中移除 State 对象时会调用,一般用在 dispose 之前
override
-
didChangeAccessibilityFeatures(
) → void -
Called when the system changes the set of currently active accessibility
features.
inherited
-
didChangeAppLifecycleState(
AppLifecycleState state) → void -
函数回调时机:1.正常切换前台/后台 2.系统级别弹窗&activity / 自定义开启弹窗&activity
1.正常切换前后台
1.1 切到后台:inactive > paused
1.2 切回前台:resumed
2.系统级别弹窗&activity / 自定义开启弹窗&activity
2.1 非全屏:展示:inactive 消失:resumed
2.1 全屏:展示:inactive > paused 消失:resumed
override
-
didChangeDependencies(
) → void -
初始化完成之后调用,BuildContext上下文可用时期
override
-
didChangeLocales(
List< Locale> ? locales) → void -
Called when the system tells the app that the user's locale has
changed. For example, if the user changes the system language
settings.
inherited
-
didChangeMetrics(
) → void -
Called when the application's dimensions change. For example,
when a phone is rotated.
inherited
-
didChangePlatformBrightness(
) → void -
Called when the platform brightness changes.
inherited
-
didChangeTextScaleFactor(
) → void -
Called when the platform's text scale factor changes.
inherited
-
didHaveMemoryPressure(
) → void -
Called when the system is running low on memory.
inherited
-
didPop(
) → void -
Called when the current route has been popped off.
inherited
-
didPopNext(
) → void -
调用时期:顶部路由弹出,当前路由显示
override
-
didPopRoute(
) → Future< bool> -
Called when the system tells the app to pop the current route, such as
after a system back button press or back gesture.
inherited
-
didPush(
) → void -
Called when the current route has been pushed.
inherited
-
didPushNext(
) → void -
调用时期:新的路由添加入栈,当前路由不再可见
override
-
didPushRoute(
String route) → Future< bool> -
Called when the host tells the application to push a new route onto the
navigator.
inherited
-
didPushRouteInformation(
RouteInformation routeInformation) → Future< bool> -
Called when the host tells the application to push a new
RouteInformation and a restoration state onto the router.
inherited
-
didRequestAppExit(
) → Future< AppExitResponse> -
Called when a request is received from the system to exit the application.
inherited
-
dispose(
) → void -
Widget 被销毁时,通常会在此方法中移除监听或清理数据等,整个生命周期只会执行一次
override
-
getLifecycle(
) → LifecycleObservable -
Lifecycle被观察者
override
-
getStateful(
) → State< StatefulWidget> -
Lifecycle stateful对象
override
-
handleCancelBackGesture(
) → void -
Called when a predictive back gesture is canceled, indicating that no
navigation should occur.
inherited
-
handleCommitBackGesture(
) → void -
Called when a predictive back gesture is finished successfully, indicating
that the current route should be popped.
inherited
-
handleStartBackGesture(
PredictiveBackEvent backEvent) → bool -
Called at the start of a predictive back gesture.
inherited
-
handleUpdateBackGestureProgress(
PredictiveBackEvent backEvent) → void -
Called when a predictive back gesture moves.
inherited
-
initState(
) → void -
初始化状态,只执行一次,BuildContext 不可用
类似于 Android 的 onCreate ,iOS 的 viewDidLoad
备注:此时view并没有渲染,statefulWidget 已经被加载到渲染树中
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited