|
@@ -30,9 +30,10 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
|
|
|
// Total timer duration in seconds (for progress calculation)
|
|
|
int _totalDurationSeconds = 0;
|
|
|
-
|
|
|
+
|
|
|
// Background services
|
|
|
- final BackgroundTimerService _backgroundTimerService = BackgroundTimerService();
|
|
|
+ final BackgroundTimerService _backgroundTimerService =
|
|
|
+ BackgroundTimerService();
|
|
|
final NotificationManager _notificationManager = NotificationManager();
|
|
|
|
|
|
// Settings
|
|
@@ -75,11 +76,11 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
// No additional handling required as background service handles the state
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// Restore timer state from persistent storage
|
|
|
Future<void> _restoreTimerState() async {
|
|
|
final timerData = await TimerData.load();
|
|
|
-
|
|
|
+
|
|
|
if (timerData.isRunning) {
|
|
|
setState(() {
|
|
|
timerState = TimerState.running;
|
|
@@ -94,7 +95,7 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// Initialize the background timer service
|
|
|
Future<void> _initializeBackgroundTimer() async {
|
|
|
await _backgroundTimerService.initialize(
|
|
@@ -123,8 +124,14 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
setState(() {
|
|
|
timerState = TimerState.running;
|
|
|
});
|
|
|
- _backgroundTimerService.resumeTimer(_remainingSeconds, _totalDurationSeconds);
|
|
|
+ _backgroundTimerService.resumeTimer(
|
|
|
+ _remainingSeconds, _totalDurationSeconds);
|
|
|
} else {
|
|
|
+ // 获取界面输入的时间
|
|
|
+ _hours = _hoursController.selectedItem;
|
|
|
+ _minutes = _minutesController.selectedItem;
|
|
|
+ _seconds = _secondsController.selectedItem;
|
|
|
+ // 计算总秒数
|
|
|
final totalSeconds = _hours * 3600 + _minutes * 60 + _seconds;
|
|
|
if (totalSeconds <= 0) return;
|
|
|
|
|
@@ -133,7 +140,7 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
_remainingSeconds = totalSeconds;
|
|
|
_totalDurationSeconds = totalSeconds;
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
_backgroundTimerService.startTimer(totalSeconds);
|
|
|
}
|
|
|
}
|
|
@@ -438,63 +445,60 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
ValueChanged<int> onChanged,
|
|
|
String unit,
|
|
|
) {
|
|
|
- return Column(
|
|
|
- children: [
|
|
|
- Expanded(
|
|
|
- child: Container(
|
|
|
- decoration: BoxDecoration(
|
|
|
- border: Border(
|
|
|
- top: BorderSide(color: Colors.grey.withOpacity(0.3), width: 1),
|
|
|
- bottom:
|
|
|
- BorderSide(color: Colors.grey.withOpacity(0.3), width: 1),
|
|
|
+ return Container(
|
|
|
+ height: 400,
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ border: Border(
|
|
|
+ top: BorderSide(color: Colors.grey.withOpacity(0.3), width: 1),
|
|
|
+ bottom: BorderSide(color: Colors.grey.withOpacity(0.3), width: 1),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ child: Stack(
|
|
|
+ children: [
|
|
|
+ // Center highlight
|
|
|
+ Positioned.fill(
|
|
|
+ child: Center(
|
|
|
+ child: Container(
|
|
|
+ height: 50,
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: Colors.blue.withOpacity(0.1),
|
|
|
+ borderRadius: BorderRadius.circular(8),
|
|
|
+ ),
|
|
|
),
|
|
|
),
|
|
|
- child: Stack(
|
|
|
- children: [
|
|
|
- // Center highlight
|
|
|
- Positioned.fill(
|
|
|
- child: Center(
|
|
|
- child: Container(
|
|
|
- height: 50,
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: Colors.blue.withOpacity(0.1),
|
|
|
- borderRadius: BorderRadius.circular(8),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ListWheelScrollView(
|
|
|
- controller: controller,
|
|
|
- physics: FixedExtentScrollPhysics(),
|
|
|
- diameterRatio: 1.5,
|
|
|
- itemExtent: 50,
|
|
|
- children: items.map((value) {
|
|
|
- return Center(
|
|
|
- child: Text(
|
|
|
- value.toString().padLeft(2, '0'),
|
|
|
- style: TextStyle(
|
|
|
- fontSize: 30,
|
|
|
- color: Colors.black,
|
|
|
- fontWeight: FontWeight.w500,
|
|
|
- ),
|
|
|
- ),
|
|
|
- );
|
|
|
- }).toList(),
|
|
|
- onSelectedItemChanged: onChanged,
|
|
|
- ),
|
|
|
- ],
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ alignment: Alignment.centerRight,
|
|
|
+ padding: EdgeInsets.only(right: 15),
|
|
|
+ child: Text(
|
|
|
+ unit,
|
|
|
+ style: TextStyle(
|
|
|
+ fontSize: 18,
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ ),
|
|
|
),
|
|
|
),
|
|
|
- ),
|
|
|
- SizedBox(height: 8),
|
|
|
- Text(
|
|
|
- unit,
|
|
|
- style: TextStyle(
|
|
|
- fontSize: 18,
|
|
|
- fontWeight: FontWeight.bold,
|
|
|
+ ListWheelScrollView(
|
|
|
+ controller: controller,
|
|
|
+ physics: FixedExtentScrollPhysics(),
|
|
|
+ diameterRatio: 1.5,
|
|
|
+ itemExtent: 50,
|
|
|
+ children: items.map((value) {
|
|
|
+ return Center(
|
|
|
+ child: Text(
|
|
|
+ value.toString().padLeft(2, '0'),
|
|
|
+ style: TextStyle(
|
|
|
+ fontSize: 30,
|
|
|
+ color: Colors.black,
|
|
|
+ fontWeight: FontWeight.w500,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }).toList(),
|
|
|
+ onSelectedItemChanged: onChanged,
|
|
|
),
|
|
|
- ),
|
|
|
- ],
|
|
|
+ ],
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
}
|