From 85c5534aa3c15b5f244006d9e78a94304408cb03 Mon Sep 17 00:00:00 2001 From: Santhoshkumargontla Date: Tue, 24 Feb 2026 20:47:35 +0530 Subject: [PATCH] Fix TimerRingController await misuse and null-safe timer cancel --- .../controllers/timer_ring_controller.dart | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/app/modules/timerRing/controllers/timer_ring_controller.dart b/lib/app/modules/timerRing/controllers/timer_ring_controller.dart index 045220c26..f38045d5f 100644 --- a/lib/app/modules/timerRing/controllers/timer_ring_controller.dart +++ b/lib/app/modules/timerRing/controllers/timer_ring_controller.dart @@ -12,12 +12,14 @@ class TimerRingController extends GetxController { MethodChannel timerChannel = const MethodChannel('timer'); Timer? vibrationTimer; late StreamSubscription _subscription; - getFakeTimerModel()async { - TimerModel fakeTimer = await Utils.genFakeTimerModel(); - return fakeTimer; + + Future getFakeTimerModel() async { + TimerModel fakeTimer = await Utils.genFakeTimerModel(); + return fakeTimer; } + @override - void onInit() async { + Future onInit() async { super.onInit(); // Preventing app from being minimized! @@ -30,17 +32,19 @@ class TimerRingController extends GetxController { Timer.periodic(const Duration(milliseconds: 3500), (Timer timer) { Vibration.vibrate(pattern: [500, 3000]); }); - AudioUtils.playTimer(alarmRecord: await getFakeTimerModel().value); + final timerRecord = await getFakeTimerModel(); + AudioUtils.playTimer(alarmRecord: timerRecord); await timerChannel.invokeMethod('cancelTimer'); } @override - onClose() async { + Future onClose() async { Vibration.cancel(); - vibrationTimer!.cancel(); + vibrationTimer?.cancel(); + final timerRecord = await getFakeTimerModel(); AudioUtils.stopTimer( - ringtoneName: await getFakeTimerModel().ringtoneName, + ringtoneName: timerRecord.ringtoneName, ); _subscription.cancel(); super.onClose();