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) {
|
if (value) {
|
||||||
await _scheduleAlarm();
|
await _scheduleAlarm();
|
||||||
} else {
|
} else {
|
||||||
_alarmTimer?.cancel();
|
_stopAlarm();
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
void _showSnack(String msg) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
|
||||||
}
|
}
|
||||||
@@ -462,6 +470,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
|
if (v == "") {
|
||||||
|
_stopAlarm();
|
||||||
|
}
|
||||||
final val = _validateTime(v);
|
final val = _validateTime(v);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
_savePrefs();
|
_savePrefs();
|
||||||
@@ -538,10 +549,15 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
_alarmEnabled
|
_alarmEnabled
|
||||||
? '${_minutesBefore} Minute${_plural} Before @ $_alarmDisplayTime'
|
? '${_minutesBefore} Minute${_plural} Before @ $_alarmDisplayTime'
|
||||||
: '',
|
: (_sunsetController.text == ""
|
||||||
|
? "Time Missing"
|
||||||
|
: ""),
|
||||||
),
|
),
|
||||||
value: _alarmEnabled,
|
value:
|
||||||
onChanged: _toggleAlarm,
|
_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