|
@@ -6,7 +6,6 @@ import 'package:flutter_clock/pages/timer/timer_settings_page.dart';
|
|
|
import 'package:flutter_clock/utils/audio_manager.dart';
|
|
|
import 'package:flutter_clock/utils/screen_manager.dart';
|
|
|
import 'package:flutter_clock/utils/background_timer_service.dart';
|
|
|
-import 'package:flutter_clock/utils/notification_manager.dart';
|
|
|
|
|
|
/// Description: 倒计时页面
|
|
|
/// Time : 04/06/2025 Sunday
|
|
@@ -34,7 +33,6 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
// Background services
|
|
|
final BackgroundTimerService _backgroundTimerService =
|
|
|
BackgroundTimerService();
|
|
|
- final NotificationManager _notificationManager = NotificationManager();
|
|
|
|
|
|
// Settings
|
|
|
late TimerSettings _settings;
|
|
@@ -119,18 +117,30 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
}
|
|
|
|
|
|
/// Start a new timer or resume an existing paused timer
|
|
|
- void _startTimer(bool resumed) {
|
|
|
- if (resumed) {
|
|
|
+ void _startTimer(String status) {
|
|
|
+ if (status == "resume") {
|
|
|
setState(() {
|
|
|
timerState = TimerState.running;
|
|
|
});
|
|
|
_backgroundTimerService.resumeTimer(
|
|
|
_remainingSeconds, _totalDurationSeconds);
|
|
|
- } else {
|
|
|
+ } else if (status == "start") {
|
|
|
// 获取界面输入的时间
|
|
|
- _hours = _hoursController.selectedItem;
|
|
|
- _minutes = _minutesController.selectedItem;
|
|
|
- _seconds = _secondsController.selectedItem;
|
|
|
+ int _hourstmp = _hoursController.selectedItem;
|
|
|
+ int _minutestmp = _minutesController.selectedItem;
|
|
|
+ int _secondstmp = _secondsController.selectedItem;
|
|
|
+ // 计算总秒数
|
|
|
+ final totalSeconds = _hourstmp * 3600 + _minutestmp * 60 + _secondstmp;
|
|
|
+ if (totalSeconds <= 0) return;
|
|
|
+
|
|
|
+ setState(() {
|
|
|
+ timerState = TimerState.running;
|
|
|
+ _remainingSeconds = totalSeconds;
|
|
|
+ _totalDurationSeconds = totalSeconds;
|
|
|
+ });
|
|
|
+
|
|
|
+ _backgroundTimerService.startTimer(totalSeconds);
|
|
|
+ } else if (status == "loop") {
|
|
|
// 计算总秒数
|
|
|
final totalSeconds = _hours * 3600 + _minutes * 60 + _seconds;
|
|
|
if (totalSeconds <= 0) return;
|
|
@@ -158,7 +168,6 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
_backgroundTimerService.cancelTimer();
|
|
|
_audioManager.stopSound();
|
|
|
_audioManager.stopVibration();
|
|
|
- _notificationManager.stopVibration();
|
|
|
setState(() {
|
|
|
timerState = TimerState.prepare;
|
|
|
});
|
|
@@ -172,17 +181,17 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
|
|
|
// Play sound and vibrate
|
|
|
if (_settings.vibrate) {
|
|
|
- _notificationManager.notifyTimerCompletion();
|
|
|
+ _audioManager.triggerVibration();
|
|
|
}
|
|
|
_audioManager.playSound(_settings.sound, _settings.volume, _settings.loop);
|
|
|
-
|
|
|
+
|
|
|
// If loop is enabled, restart the timer
|
|
|
if (_settings.loop) {
|
|
|
Future.delayed(Duration(seconds: 5), () {
|
|
|
_audioManager.stopSound();
|
|
|
- _notificationManager.stopVibration();
|
|
|
+ _audioManager.stopVibration();
|
|
|
});
|
|
|
- _startTimer(false);
|
|
|
+ _startTimer("loop");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -272,7 +281,7 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
_buildCircleButton(
|
|
|
Icons.play_arrow,
|
|
|
Colors.blue,
|
|
|
- () => _startTimer(false),
|
|
|
+ () => _startTimer("start"),
|
|
|
),
|
|
|
_buildCircleButton(
|
|
|
Icons.settings,
|
|
@@ -399,7 +408,7 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
: _buildCircleButton(
|
|
|
Icons.play_arrow,
|
|
|
Colors.blue,
|
|
|
- () => _startTimer(true),
|
|
|
+ () => _startTimer("resume"),
|
|
|
),
|
|
|
// 重置
|
|
|
_buildCircleButton(
|