class FlutterLifeCycleState extends State<FlutterLifeCycle>
with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this); //添加觀察者
}
///生命周期變化時(shí)回調(diào)
// resumed:應(yīng)用可見(jiàn)并可響應(yīng)用戶(hù)操作
// inactive:用戶(hù)可見(jiàn),但不可響應(yīng)用戶(hù)操作
// paused:已經(jīng)暫停了崖瞭,用戶(hù)不可見(jiàn)银受、不可操作
// suspending:應(yīng)用被掛起鞋囊,此狀態(tài)IOS永遠(yuǎn)不會(huì)回調(diào)
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
print("@@@@@@@@@ didChangeAppLifecycleState: $state");
}
///當(dāng)前系統(tǒng)改變了一些訪問(wèn)性活動(dòng)的回調(diào)
@override
void didChangeAccessibilityFeatures() {
super.didChangeAccessibilityFeatures();
print("@@@@@@@@@ didChangeAccessibilityFeatures");
}
/// Called when the system is running low on memory.
///低內(nèi)存回調(diào)
@override
void didHaveMemoryPressure() {
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.
///用戶(hù)本地設(shè)置變化時(shí)調(diào)用晃痴,如系統(tǒng)語(yǔ)言改變
@override
void didChangeLocales(List<Locale> locale) {
super.didChangeLocales(locale);
print("@@@@@@@@@ didChangeLocales");
}
/// Called when the application's dimensions change. For example,
/// when a phone is rotated.
///應(yīng)用尺寸改變時(shí)回調(diào),例如旋轉(zhuǎn)
@override
void didChangeMetrics() {
super.didChangeMetrics();
Size size = WidgetsBinding.instance.window.physicalSize;
print("@@@@@@@@@ didChangeMetrics :寬:${size.width} 高:${size.height}");
}
/// {@macro on_platform_brightness_change}
@override
void didChangePlatformBrightness() {
super.didChangePlatformBrightness();
print("@@@@@@@@@ didChangePlatformBrightness");
}
///文字系數(shù)變化
@override
void didChangeTextScaleFactor() {
super.didChangeTextScaleFactor();
print(
"@@@@@@@@@ didChangeTextScaleFactor :${WidgetsBinding.instance.window.textScaleFactor}");
}
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: Text("flutter"),
),
);
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this); //銷(xiāo)毀觀察者
}
}
//屏幕旋轉(zhuǎn)
//豎屏切橫屏
//2019-05-22 09:04:58.350 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeLocales
//2019-05-22 09:04:58.353 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeTextScaleFactor :1.0
//2019-05-22 09:04:58.354 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangePlatformBrightness
//2019-05-22 09:04:58.401 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeLocales
//2019-05-22 09:04:58.402 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeTextScaleFactor :1.0
//2019-05-22 09:04:58.402 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangePlatformBrightness
//2019-05-22 09:04:58.404 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeMetrics :寬:1080.0 高:2280.0
//2019-05-22 09:04:58.405 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeMetrics :寬:2198.0 高:1080.0
//橫屏切豎屏
//2019-05-22 09:05:05.714 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeLocales
//2019-05-22 09:05:05.715 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeTextScaleFactor :1.0
//2019-05-22 09:05:05.715 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangePlatformBrightness
//2019-05-22 09:05:05.766 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeLocales
//2019-05-22 09:05:05.767 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeTextScaleFactor :1.0
//2019-05-22 09:05:05.767 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangePlatformBrightness
//2019-05-22 09:05:05.768 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeMetrics :寬:2198.0 高:1080.0
//2019-05-22 09:05:05.769 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeMetrics :寬:1080.0 高:2280.0
//改變系統(tǒng)語(yǔ)言侮攀,回到應(yīng)用才調(diào)用以下方法
//2019-05-22 09:08:04.428 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeLocales
//2019-05-22 09:08:04.429 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangeTextScaleFactor :1.0
//2019-05-22 09:08:04.429 27881-27901/com.yourcompany.test1 I/flutter: @@@@@@@@@ didChangePlatformBrightness
// inactive:用戶(hù)可見(jiàn)倦沧,但不可響應(yīng)用戶(hù)操作
// resumed:應(yīng)用可見(jiàn)并可響應(yīng)用戶(hù)操作
// paused:已經(jīng)暫停了,用戶(hù)不可見(jiàn)墩弯、不可操作
// suspending:應(yīng)用被掛起吩跋,此狀態(tài)IOS永遠(yuǎn)不會(huì)回調(diào)
// Home鍵退出,鎖屏
// 2019-05-22 08:29:26.321 27526-27546/com.yourcompany.test1 I/flutter: AppLifecycleState.inactive
// 2019-05-22 08:29:26.378 27526-27546/com.yourcompany.test1 I/flutter: AppLifecycleState.paused
// Home鍵退出后再點(diǎn)擊應(yīng)用圖標(biāo)啟動(dòng)渔工,解鎖屏幕
// 2019-05-22 08:30:37.533 27526-27546/com.yourcompany.test1 I/flutter: AppLifecycleState.inactive
// 2019-05-22 08:30:37.535 27526-27546/com.yourcompany.test1 I/flutter: AppLifecycleState.resumed
// 進(jìn)入該頁(yè)面或者back鍵退出該頁(yè)面锌钮,沒(méi)有調(diào)用didChangeAppLifecycleState方法
碼云地址:https://gitee.com/xgljh/Flutter.git
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者