美文网首页
Flutter StatefulWidget 生命周期的监听

Flutter StatefulWidget 生命周期的监听

作者: krcm110 | 来源:发表于2020-01-10 09:32 被阅读0次

    classFlutterLifeCycleStateextendsState<FlutterLifeCycle>withWidgetsBindingObserver{@overridevoidinitState(){super.initState();WidgetsBinding.instance.addObserver(this);//添加观察者}///生命周期变化时回调// resumed:应用可见并可响应用户操作// inactive:用户可见,但不可响应用户操作// paused:已经暂停了,用户不可见、不可操作// suspending:应用被挂起,此状态IOS永远不会回调@overridevoiddidChangeAppLifecycleState(AppLifecycleStatestate){super.didChangeAppLifecycleState(state);print("@@@@@@@@@ didChangeAppLifecycleState: $state");}///当前系统改变了一些访问性活动的回调@overridevoiddidChangeAccessibilityFeatures(){super.didChangeAccessibilityFeatures();print("@@@@@@@@@ didChangeAccessibilityFeatures");}/// Called when the system is running low on memory.///低内存回调@overridevoiddidHaveMemoryPressure(){super.didHaveMemoryPressure();print("@@@@@@@@@ didHaveMemoryPressure");}/// Called when the system tells the app that the user's locale has/// changed. For example, if the user changes the system language/// settings.///用户本地设置变化时调用,如系统语言改变@overridevoiddidChangeLocales(List<Locale>locale){super.didChangeLocales(locale);print("@@@@@@@@@ didChangeLocales");}/// Called when the application's dimensions change. For example,/// when a phone is rotated.///应用尺寸改变时回调,例如旋转@overridevoiddidChangeMetrics(){super.didChangeMetrics();Sizesize=WidgetsBinding.instance.window.physicalSize;print("@@@@@@@@@ didChangeMetrics :宽:${size.width} 高:${size.height}");}/// {@macro on_platform_brightness_change}@overridevoiddidChangePlatformBrightness(){super.didChangePlatformBrightness();print("@@@@@@@@@ didChangePlatformBrightness");}///文字系数变化@overridevoiddidChangeTextScaleFactor(){super.didChangeTextScaleFactor();print("@@@@@@@@@ didChangeTextScaleFactor :${WidgetsBinding.instance.window.textScaleFactor}");}@overrideWidgetbuild(BuildContextcontext){returnContainer(child:Center(child:Text("flutter"),),);}@overridevoiddispose(){super.dispose();WidgetsBinding.instance.removeObserver(this);//销毁观察者}}

    https://www.jianshu.com/p/2fd5562c1c9bWidgetsBindingObserver监测页面生命周期 - 简书

    相关文章

      网友评论

          本文标题:Flutter StatefulWidget 生命周期的监听

          本文链接:https://www.haomeiwen.com/subject/xskpactx.html