倒计时 息屏,后台运行
定义了后台服务:
class BackgroundTimerService { Isolate? _isolate; ReceivePort? _receivePort; SendPort? _sendPort;
TimerPage 使用后台服务:
final BackgroundTimerService _backgroundTimerService = BackgroundTimerService(); final NotificationManager _notificationManager = NotificationManager(); void _startTimer(bool resumed) { if (resumed) { setState(() { timerState = TimerState.running; }); _backgroundTimerService.resumeTimer(_remainingSeconds, _totalDurationSeconds); } else { final totalSeconds = _hours * 3600 + _minutes * 60 + _seconds; if (totalSeconds <= 0) return; setState(() { timerState = TimerState.running; _remainingSeconds = totalSeconds; _totalDurationSeconds = totalSeconds; }); _backgroundTimerService.startTimer(totalSeconds); } }
提示用户设置,电池跳过优化
目前熄屏后,时间就不走了,只有打开屏幕才继续倒计时
倒计时 息屏,后台运行
定义了后台服务:
TimerPage 使用后台服务:
提示用户设置,电池跳过优化
目前熄屏后,时间就不走了,只有打开屏幕才继续倒计时