import 'package:flutter/widgets.dart'; import 'package:star_lock/talk/startChart/start_chart_manage.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.'); StartChartManage().destruction(); } void onAppResumed() { // 处理应用程序恢复到前台的逻辑 StartChartManage().init(); print('App has resumed to the foreground.'); } void onAppDetached() { // 处理应用程序被杀死的逻辑 StartChartManage().destruction(); print('App has been detached.'); } }