main, disable the slide switch if the time is missing, stop the alarm if the time is completely backed out.
This commit is contained in:
1 parent
2606116c62
commit
183634dee5
1 file changed
+28
-12
+28
-12
@@ -327,18 +327,26 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
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<void> _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<HomeScreen> {
|
||||
),
|
||||
),
|
||||
onChanged: (v) {
|
||||
if (v == "") {
|
||||
_stopAlarm();
|
||||
}
|
||||
final val = _validateTime(v);
|
||||
if (val == null) {
|
||||
_savePrefs();
|
||||
@@ -538,10 +549,15 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user