From 6c1781b55cd3be7b8c51654c17ef9affc7908fe7 Mon Sep 17 00:00:00 2001 From: rohitarer Date: Mon, 27 Oct 2025 19:34:20 +0530 Subject: [PATCH 1/2] fix(timer-ring): call getFakeTimerModel() correctly (await result; remove .value) to prevent crash on ring start --- .../debug/controllers/debug_controller.dart | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/lib/app/modules/debug/controllers/debug_controller.dart b/lib/app/modules/debug/controllers/debug_controller.dart index d2cc4aa70..5c7b64429 100644 --- a/lib/app/modules/debug/controllers/debug_controller.dart +++ b/lib/app/modules/debug/controllers/debug_controller.dart @@ -1,7 +1,5 @@ import 'package:get/get.dart'; import 'package:flutter/material.dart'; -import 'package:get/get_rx/get_rx.dart'; -import 'package:get/get_rx/src/rx_types/rx_types.dart'; import 'dart:async'; import '../../../data/providers/isar_provider.dart'; import '../../../modules/settings/controllers/theme_controller.dart'; @@ -12,14 +10,14 @@ import '../../../data/models/debug_model.dart'; class DebugController extends GetxController { final ThemeController themeController = Get.find(); final TextEditingController searchController = TextEditingController(); - + var logs = >[].obs; var filteredLogs = >[].obs; var selectedLogLevel = Rxn(); var startDate = Rxn(); var endDate = Rxn(); RxBool isDevMode = false.obs; - + Timer? _timer; @override @@ -48,7 +46,8 @@ class DebugController extends GetxController { final fetchedLogs = await IsarDb().getLogs(); logs.value = fetchedLogs.reversed.toList(); applyFilters(); - debugPrint('Debug screen: Successfully loaded ${fetchedLogs.length} logs'); + debugPrint( + 'Debug screen: Successfully loaded ${fetchedLogs.length} logs',); } catch (e) { debugPrint('Debug screen: Error loading logs: $e'); Get.snackbar( @@ -63,17 +62,22 @@ class DebugController extends GetxController { void applyFilters() { filteredLogs.value = logs.where((log) { bool matchesSearch = searchController.text.isEmpty || - log['Status'].toString().toLowerCase().contains(searchController.text.toLowerCase()) || + log['Status'] + .toString() + .toLowerCase() + .contains(searchController.text.toLowerCase()) || log['LogID'].toString().contains(searchController.text) || - Utils.getFormattedDate(DateTime.fromMillisecondsSinceEpoch(log['LogTime'])) + Utils.getFormattedDate( + DateTime.fromMillisecondsSinceEpoch(log['LogTime']),) .toLowerCase() .contains(searchController.text.toLowerCase()); - + bool matchesLevel = selectedLogLevel.value == null; if (selectedLogLevel.value != null) { final status = log['Status'].toString().toLowerCase(); - debugPrint('Checking log: "$status" for level: ${selectedLogLevel.value}'); - + debugPrint( + 'Checking log: "$status" for level: ${selectedLogLevel.value}',); + switch (selectedLogLevel.value!) { case LogLevel.error: matchesLevel = status.contains('error'); @@ -82,23 +86,27 @@ class DebugController extends GetxController { matchesLevel = status.contains('warning'); break; case LogLevel.info: - matchesLevel = !status.contains('error') && !status.contains('warning'); + matchesLevel = + !status.contains('error') && !status.contains('warning'); break; } debugPrint('Matches level: $matchesLevel'); } - + bool matchesDateRange = true; if (startDate.value != null && endDate.value != null) { final logTime = DateTime.fromMillisecondsSinceEpoch(log['LogTime']); - final startOfDay = DateTime(startDate.value!.year, startDate.value!.month, startDate.value!.day); - final endOfDay = DateTime(endDate.value!.year, endDate.value!.month, endDate.value!.day, 23, 59, 59); - matchesDateRange = logTime.isAfter(startOfDay) && logTime.isBefore(endOfDay); + final startOfDay = DateTime(startDate.value!.year, + startDate.value!.month, startDate.value!.day,); + final endOfDay = DateTime(endDate.value!.year, endDate.value!.month, + endDate.value!.day, 23, 59, 59,); + matchesDateRange = + logTime.isAfter(startOfDay) && logTime.isBefore(endOfDay); } - + return matchesSearch && matchesLevel && matchesDateRange; }).toList(); - + debugPrint('Total logs: ${logs.length}'); debugPrint('Filtered logs: ${filteredLogs.length}'); if (filteredLogs.isEmpty) { @@ -136,7 +144,8 @@ class DebugController extends GetxController { firstDate: DateTime(2020), lastDate: DateTime.now(), initialDateRange: DateTimeRange( - start: startDate.value ?? DateTime.now().subtract(const Duration(days: 7)), + start: + startDate.value ?? DateTime.now().subtract(const Duration(days: 7)), end: endDate.value ?? DateTime.now(), ), builder: (context, child) { @@ -147,15 +156,16 @@ class DebugController extends GetxController { onPrimary: Colors.white, surface: themeController.secondaryBackgroundColor.value, onSurface: themeController.primaryTextColor.value, - background: themeController.primaryBackgroundColor.value, - onBackground: themeController.primaryTextColor.value, ), textButtonTheme: TextButtonThemeData( style: TextButton.styleFrom( foregroundColor: kprimaryColor, ), ), - dialogBackgroundColor: themeController.secondaryBackgroundColor.value, + // ⬇️ was DialogThemeData(...), should be DialogTheme(...) + dialogTheme: DialogThemeData( + backgroundColor: themeController.secondaryBackgroundColor.value, + ), ), child: child!, ); @@ -174,4 +184,4 @@ class DebugController extends GetxController { if (status.contains('warning')) return Colors.orange; return Colors.green; } -} \ No newline at end of file +} From 142224444a8d186e530e1ffa7aef827757f08d0d Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 27 Oct 2025 19:44:39 +0530 Subject: [PATCH 2/2] fix(timer-ring): correct async getFakeTimerModel() usage and cleanup onClose() --- .../controllers/timer_ring_controller.dart | 90 +++++++++++++++---- 1 file changed, 73 insertions(+), 17 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..d06e60642 100644 --- a/lib/app/modules/timerRing/controllers/timer_ring_controller.dart +++ b/lib/app/modules/timerRing/controllers/timer_ring_controller.dart @@ -9,40 +9,96 @@ import 'package:ultimate_alarm_clock/app/utils/utils.dart'; import 'package:vibration/vibration.dart'; class TimerRingController extends GetxController { - MethodChannel timerChannel = const MethodChannel('timer'); + final MethodChannel timerChannel = const MethodChannel('timer'); Timer? vibrationTimer; - late StreamSubscription _subscription; - getFakeTimerModel()async { - TimerModel fakeTimer = await Utils.genFakeTimerModel(); - return fakeTimer; + late final StreamSubscription _subscription; + + Future getFakeTimerModel() async { + return Utils.genFakeTimerModel(); } + @override - void onInit() async { + Future onInit() async { super.onInit(); - // Preventing app from being minimized! + // Keep app foregrounded while ringing _subscription = FGBGEvents.stream.listen((event) { if (event == FGBGType.background) { timerChannel.invokeMethod('bringAppToForeground'); } }); - vibrationTimer = - Timer.periodic(const Duration(milliseconds: 3500), (Timer timer) { - Vibration.vibrate(pattern: [500, 3000]); + + vibrationTimer = Timer.periodic(const Duration(milliseconds: 3500), (_) { + Vibration.vibrate(pattern: const [500, 3000]); }); - AudioUtils.playTimer(alarmRecord: await getFakeTimerModel().value); + + final model = await getFakeTimerModel(); // FIX: no .value + AudioUtils.playTimer(alarmRecord: model); // FIX await timerChannel.invokeMethod('cancelTimer'); } @override - onClose() async { + Future onClose() async { Vibration.cancel(); - vibrationTimer!.cancel(); - AudioUtils.stopTimer( - ringtoneName: await getFakeTimerModel().ringtoneName, - ); - _subscription.cancel(); + vibrationTimer?.cancel(); // FIX: null-safe + + final model = await getFakeTimerModel(); // FIX: await once + AudioUtils.stopTimer(ringtoneName: model.ringtoneName); // FIX + + await _subscription.cancel(); super.onClose(); } } + + + + +// import 'dart:async'; + +// import 'package:flutter/services.dart'; +// import 'package:flutter_fgbg/flutter_fgbg.dart'; +// import 'package:get/get.dart'; +// import 'package:ultimate_alarm_clock/app/data/models/timer_model.dart'; +// import 'package:ultimate_alarm_clock/app/utils/audio_utils.dart'; +// import 'package:ultimate_alarm_clock/app/utils/utils.dart'; +// import 'package:vibration/vibration.dart'; + +// class TimerRingController extends GetxController { +// MethodChannel timerChannel = const MethodChannel('timer'); +// Timer? vibrationTimer; +// late StreamSubscription _subscription; +// getFakeTimerModel()async { +// TimerModel fakeTimer = await Utils.genFakeTimerModel(); +// return fakeTimer; +// } +// @override +// void onInit() async { +// super.onInit(); + +// // Preventing app from being minimized! +// _subscription = FGBGEvents.stream.listen((event) { +// if (event == FGBGType.background) { +// timerChannel.invokeMethod('bringAppToForeground'); +// } +// }); +// vibrationTimer = +// Timer.periodic(const Duration(milliseconds: 3500), (Timer timer) { +// Vibration.vibrate(pattern: [500, 3000]); +// }); +// AudioUtils.playTimer(alarmRecord: await getFakeTimerModel().value); + +// await timerChannel.invokeMethod('cancelTimer'); +// } + +// @override +// onClose() async { +// Vibration.cancel(); +// vibrationTimer!.cancel(); +// AudioUtils.stopTimer( +// ringtoneName: await getFakeTimerModel().ringtoneName, +// ); +// _subscription.cancel(); +// super.onClose(); +// } +// }