66 lines
2.1 KiB
Dart
66 lines
2.1 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/network/start_chart_api.dart';
|
|
import 'package:star_lock/talk/starChart/constant/talk_status.dart';
|
|
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
|
|
class AppLifecycleObserver extends WidgetsBindingObserver {
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
super.didChangeAppLifecycleState(state);
|
|
|
|
// 打印应用程序生命周期状态
|
|
print('AppLifecycleState: $state');
|
|
|
|
// 根据应用程序状态执行相应的操作
|
|
if (state == AppLifecycleState.paused) {
|
|
// 应用程序进入后台
|
|
onAppPaused();
|
|
} else if (state == AppLifecycleState.resumed) {
|
|
// 应用程序恢复到前台
|
|
onAppResumed();
|
|
} else if (state == AppLifecycleState.detached) {
|
|
// 应用程序被杀死
|
|
onAppDetached();
|
|
}
|
|
}
|
|
|
|
void onAppPaused() {
|
|
// 处理应用程序进入后台的逻辑
|
|
print('App has entered the background.');
|
|
if (StartChartManage().talkStatus.status ==
|
|
TalkStatus.passiveCallWaitingAnswer ||
|
|
StartChartManage().talkStatus.status ==
|
|
TalkStatus.proactivelyCallWaitingAnswer) {
|
|
StartChartManage().startTalkHangupMessageTimer();
|
|
StartChartManage().startTalkRejectMessageTimer();
|
|
// 如果是等待接听时就退出页面
|
|
Get.back();
|
|
}
|
|
StartChartManage().destruction();
|
|
}
|
|
|
|
void onAppResumed() async {
|
|
// 处理应用程序恢复到前台的逻辑
|
|
StartChartManage().init();
|
|
final loginData = await Storage.getLoginData();
|
|
|
|
// 获取星图url
|
|
if (loginData != null &&
|
|
loginData?.starchart != null &&
|
|
loginData?.starchart?.scdUrl != null &&
|
|
loginData?.starchart?.scdUrl != '') {
|
|
StartChartApi.to.startChartHost =
|
|
loginData!.starchart!.scdUrl ?? StartChartApi.to.startChartHost;
|
|
}
|
|
print('App has resumed to the foreground.');
|
|
}
|
|
|
|
void onAppDetached() {
|
|
// 处理应用程序被杀死的逻辑
|
|
StartChartManage().destruction();
|
|
print('App has been detached.');
|
|
}
|
|
}
|