@@ -36,6 +36,7 @@ class HomeController extends GetxController {
36
36
final alarmTime = 'No upcoming alarms!' .obs;
37
37
bool refreshTimer = false ;
38
38
bool isEmpty = true ;
39
+ Timer ? _delayTimer;
39
40
Timer _timer = Timer .periodic (const Duration (milliseconds: 1 ), (timer) {});
40
41
List alarms = [].obs;
41
42
int lastRefreshTime = DateTime .now ().millisecondsSinceEpoch;
@@ -252,8 +253,9 @@ class HomeController extends GetxController {
252
253
delayToSchedule = Timer (const Duration (seconds: 1 ), () async {
253
254
lastRefreshTime = DateTime .now ().millisecondsSinceEpoch;
254
255
// Cancel timer if we have to refresh
255
- if (refreshTimer == true && _timer.isActive) {
256
- _timer.cancel ();
256
+ if (refreshTimer == true ) {
257
+ if (_timer.isActive) _timer.cancel ();
258
+ if (_delayTimer != null ) _delayTimer? .cancel ();
257
259
refreshTimer = false ;
258
260
}
259
261
@@ -276,7 +278,6 @@ class HomeController extends GetxController {
276
278
latestAlarm.days,
277
279
);
278
280
alarmTime.value = 'Rings in $timeToAlarm ' ;
279
-
280
281
// This function is necessary when alarms are deleted/enabled
281
282
await scheduleNextAlarm (
282
283
alarmRecord,
@@ -296,38 +297,38 @@ class HomeController extends GetxController {
296
297
297
298
// Adding a delay till that difference between seconds upto the next
298
299
// minute
299
- await Future .delayed (delay);
300
-
301
- // Update the value of timeToAlarm only once till it settles it's time
302
- // with the upcoming alarm
303
- // Doing this because of an bug :
304
- // If we are not doing the below three lines of code the
305
- // time is not updating for 2 min after running
306
- // Why is it happening?? -> BECAUSE OUR VALUE WILL BE UPDATED
307
- // AFTER 1 MIN ACCORDING TO BELOW TIMER WHICH WILL CAUSE
308
- // MISCALCULATION FOR INITIAL MINUTES
309
- // This is just to make sure that our calculated time-to-alarm is
310
- // upto date with the real time for next alarm
311
- timeToAlarm = Utils .timeUntilAlarm (
312
- Utils .stringToTimeOfDay (latestAlarm.alarmTime),
313
- latestAlarm.days,
314
- );
315
- alarmTime.value = 'Rings in $timeToAlarm ' ;
316
-
317
- // Running a timer of periodic one minute as it is now in sync with
318
- // the current time
319
- _timer = Timer .periodic (
320
- Duration (
321
- milliseconds: Utils .getMillisecondsToAlarm (
322
- DateTime .now (),
323
- DateTime .now ().add (const Duration (minutes: 1 )),
324
- ),
325
- ), (timer) {
300
+ _delayTimer = Timer (delay, () {
301
+ // Update the value of timeToAlarm only once till it settles it's time
302
+ // with the upcoming alarm
303
+ // Doing this because of an bug :
304
+ // If we are not doing the below three lines of code the
305
+ // time is not updating for 2 min after running
306
+ // Why is it happening?? -> BECAUSE OUR VALUE WILL BE UPDATED
307
+ // AFTER 1 MIN ACCORDING TO BELOW TIMER WHICH WILL CAUSE
308
+ // MISCALCULATION FOR INITIAL MINUTES
309
+ // This is just to make sure that our calculated time-to-alarm is
310
+ // upto date with the real time for next alarm
326
311
timeToAlarm = Utils .timeUntilAlarm (
327
312
Utils .stringToTimeOfDay (latestAlarm.alarmTime),
328
313
latestAlarm.days,
329
314
);
330
315
alarmTime.value = 'Rings in $timeToAlarm ' ;
316
+
317
+ // Running a timer of periodic one minute as it is now in sync with
318
+ // the current time
319
+ _timer = Timer .periodic (
320
+ Duration (
321
+ milliseconds: Utils .getMillisecondsToAlarm (
322
+ DateTime .now (),
323
+ DateTime .now ().add (const Duration (minutes: 1 )),
324
+ ),
325
+ ), (timer) {
326
+ timeToAlarm = Utils .timeUntilAlarm (
327
+ Utils .stringToTimeOfDay (latestAlarm.alarmTime),
328
+ latestAlarm.days,
329
+ );
330
+ alarmTime.value = 'Rings in $timeToAlarm ' ;
331
+ });
331
332
});
332
333
} else {
333
334
alarmTime.value = 'No upcoming alarms!' ;
@@ -567,7 +568,8 @@ class HomeController extends GetxController {
567
568
content: Column (
568
569
children: [
569
570
Text (
570
- 'This action will permanently delete these alarms from your device.' .tr,
571
+ 'This action will permanently delete these alarms from your device.'
572
+ .tr,
571
573
style: Theme .of (context).textTheme.bodyMedium,
572
574
textAlign: TextAlign .center,
573
575
),
@@ -583,17 +585,13 @@ class HomeController extends GetxController {
583
585
Get .back ();
584
586
},
585
587
style: ButtonStyle (
586
- backgroundColor:
587
- MaterialStateProperty .all (kprimaryColor),
588
+ backgroundColor: MaterialStateProperty .all (kprimaryColor),
588
589
),
589
590
child: Text (
590
591
'Cancel' .tr,
591
- style: Theme .of (context)
592
- .textTheme
593
- .displaySmall!
594
- .copyWith (
595
- color: kprimaryBackgroundColor,
596
- ),
592
+ style: Theme .of (context).textTheme.displaySmall! .copyWith (
593
+ color: kprimaryBackgroundColor,
594
+ ),
597
595
),
598
596
),
599
597
OutlinedButton (
@@ -613,7 +611,7 @@ class HomeController extends GetxController {
613
611
614
612
Get .offNamedUntil (
615
613
'/bottom-navigation-bar' ,
616
- (route) => route.settings.name == '/splash-screen' ,
614
+ (route) => route.settings.name == '/splash-screen' ,
617
615
);
618
616
},
619
617
style: OutlinedButton .styleFrom (
@@ -626,14 +624,11 @@ class HomeController extends GetxController {
626
624
),
627
625
child: Text (
628
626
'Okay' .tr,
629
- style: Theme .of (context)
630
- .textTheme
631
- .displaySmall!
632
- .copyWith (
633
- color: themeController.isLightMode.value
634
- ? Colors .red.withOpacity (0.9 )
635
- : Colors .red,
636
- ),
627
+ style: Theme .of (context).textTheme.displaySmall! .copyWith (
628
+ color: themeController.isLightMode.value
629
+ ? Colors .red.withOpacity (0.9 )
630
+ : Colors .red,
631
+ ),
637
632
),
638
633
),
639
634
],
0 commit comments