使用办法
with WidgetsBindingObserver
class _TestLifeCycleState extends State<TestLifeCycle> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
// TODO: implement build
return null;
}
/*路由弹出回调*/
@override
Future<bool> didPopRoute() {
// TODO: implement didPopRoute
return super.didPopRoute();
}
/*有新的路由push回调*/
@override
Future<bool> didPushRoute(String route) {
// TODO: implement didPushRoute
return super.didPushRoute(route);
}
/*当手机维度发生变化的时候 比如手机旋转*/
@override
void didChangeMetrics() {
// TODO: implement didChangeMetrics
super.didChangeMetrics();
}
/*当平台的文本缩放因子发生改变的时候*/
@override
void didChangeTextScaleFactor() {
// TODO: implement didChangeTextScaleFactor
super.didChangeTextScaleFactor();
}
/*当系统本地设置改变的时候回调 比如语言设置*/
@override
void didChangeLocales(List<Locale> locale) {
// TODO: implement didChangeLocales
super.didChangeLocales(locale);
}
/*生命周期发生变化的时候 比如app退到后台或者切换到前台*/
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
// TODO: implement didChangeAppLifecycleState
super.didChangeAppLifecycleState(state);
}
/*当系统内存很低的情况下回调*/
@override
void didHaveMemoryPressure() {
// TODO: implement didHaveMemoryPressure
super.didHaveMemoryPressure();
}
/*暂时没看懂啥意思*/
@override
void didChangeAccessibilityFeatures() {
// TODO: implement didChangeAccessibilityFeatures
super.didChangeAccessibilityFeatures();
}
}