64 lines
2.0 KiB
Dart
64 lines
2.0 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() {
|
|
// 处理应用程序进入后台的逻辑
|
|
|
|
final status = StartChartManage().talkStatus.status;
|
|
if (status == TalkStatus.passiveCallWaitingAnswer ||
|
|
status == TalkStatus.proactivelyCallWaitingAnswer ||
|
|
status == TalkStatus.answeredSuccessfully ||
|
|
status == TalkStatus.uninitialized) {
|
|
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.');
|
|
}
|
|
}
|