#4 息屏,后台运行

Open
opened 10 months ago by lyq · 3 comments
天问 commented 10 months ago

倒计时 息屏,后台运行

倒计时 息屏,后台运行
天问 commented 9 months ago
Owner

定义了后台服务:

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);
    }
  }
定义了后台服务: ``` 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); } } ```
lyq reopened 3 weeks ago
天问 commented 3 weeks ago
Owner

提示用户设置,电池跳过优化

提示用户设置,电池跳过优化
天问 commented 5 days ago
Owner

目前熄屏后,时间就不走了,只有打开屏幕才继续倒计时

目前熄屏后,时间就不走了,只有打开屏幕才继续倒计时
Sign in to join this conversation.
No Label
No Milestone
No assignee
1 Participants
Loading...
Cancel
Save
There is no content yet.