heavyrain 3 months ago
parent
commit
d3616a30dd
3 changed files with 64 additions and 62 deletions
  1. 1 1
      android/app/src/main/AndroidManifest.xml
  2. 0 2
      lib/index_page.dart
  3. 63 59
      lib/pages/timer/timer_page.dart

+ 1 - 1
android/app/src/main/AndroidManifest.xml

@@ -8,7 +8,7 @@
     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
     
    <application
-        android:label="flutter_clock"
+        android:label="Clock"
         android:icon="@drawable/ic_launcher">
         <activity
             android:name="me.yoqi.flutter.clock.MainActivity"

+ 0 - 2
lib/index_page.dart

@@ -19,7 +19,6 @@ class IndexPage extends StatefulWidget {
 
 class _IndexPageState extends State<IndexPage>
     with SingleTickerProviderStateMixin {
-
   late TabController _tabController;
   final List<Widget> _tabs = [
     Tab(child: Text('Alarm', style: TextStyle(fontSize: 16))),
@@ -95,4 +94,3 @@ class _IndexPageState extends State<IndexPage>
     return radiansFromDegrees(degrees);
   }
 }
-

+ 63 - 59
lib/pages/timer/timer_page.dart

@@ -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,
           ),
-        ),
-      ],
+        ],
+      ),
     );
   }
 }