From 183634dee55726e9ffe36e0cdeb0ab0ca9a545de Mon Sep 17 00:00:00 2001 From: Hyperling Date: Tue, 29 Sep 2026 11:57:09 -0700 Subject: [PATCH] main, disable the slide switch if the time is missing, stop the alarm if the time is completely backed out. --- lib/main.dart | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 9260cb3..3fa9123 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -327,18 +327,26 @@ class _HomeScreenState extends State { if (value) { await _scheduleAlarm(); } else { - _alarmTimer?.cancel(); - if (!Platform.isLinux) { - // Notification Method - if (ANDROID_USE_NOTIF) await _notifications.cancel(id: _alarmId); - - // Alarm Method - if (ANDROID_USE_ALARM) await Alarm.stop(_alarmId); - } - _showSnack('Alarm Cancelled'); + _stopAlarm(); } } + Future _stopAlarm() async { + if (Platform.isLinux) { + _alarmTimer?.cancel(); + } else if (Platform.isAndroid) { + // Notification Method + if (ANDROID_USE_NOTIF) { + await _notifications.cancel(id: _alarmId); + } + // Alarm Method + if (ANDROID_USE_ALARM) { + await Alarm.stop(_alarmId); + } + } + _showSnack('Alarm Cancelled'); + } + void _showSnack(String msg) { ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg))); } @@ -462,6 +470,9 @@ class _HomeScreenState extends State { ), ), onChanged: (v) { + if (v == "") { + _stopAlarm(); + } final val = _validateTime(v); if (val == null) { _savePrefs(); @@ -538,10 +549,15 @@ class _HomeScreenState extends State { subtitle: Text( _alarmEnabled ? '${_minutesBefore} Minute${_plural} Before @ $_alarmDisplayTime' - : '', + : (_sunsetController.text == "" + ? "Time Missing" + : ""), ), - value: _alarmEnabled, - onChanged: _toggleAlarm, + value: + _sunsetController.text != "" ? _alarmEnabled : false, + // If _isDataLoaded is false, onChanged is null, disabling the switch + onChanged: + _sunsetController.text != "" ? _toggleAlarm : null, ), ), ],