Change alarm display code to ensure we're hitting the Android section.
This commit is contained in:
1 parent
dfca094c95
commit
aade4fd7f2
1 file changed
+4
-1
+4
-1
@@ -173,6 +173,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
Timer? _alarmTimer;
|
Timer? _alarmTimer;
|
||||||
|
|
||||||
Future<void> _scheduleAlarm() async {
|
Future<void> _scheduleAlarm() async {
|
||||||
|
// Ensure that Android has the correct permissions enabled.
|
||||||
final canSchedule = await android?.canScheduleExactNotifications();
|
final canSchedule = await android?.canScheduleExactNotifications();
|
||||||
if (canSchedule != true) {
|
if (canSchedule != true) {
|
||||||
_showSnack('Permissions not yet granted, requesting...');
|
_showSnack('Permissions not yet granted, requesting...');
|
||||||
@@ -220,7 +221,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
_showSnack(
|
_showSnack(
|
||||||
'Alarm set for ${alarmTime.hour.toString().padLeft(2, '0')}:${alarmTime.minute.toString().padLeft(2, '0')} (app must stay open)',
|
'Alarm set for ${alarmTime.hour.toString().padLeft(2, '0')}:${alarmTime.minute.toString().padLeft(2, '0')} (app must stay open)',
|
||||||
);
|
);
|
||||||
} else {
|
} else if (Platform.isAndroid) {
|
||||||
// Android: use zonedSchedule (works in background)
|
// Android: use zonedSchedule (works in background)
|
||||||
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
|
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
|
||||||
const androidDetails = AndroidNotificationDetails(
|
const androidDetails = AndroidNotificationDetails(
|
||||||
@@ -243,6 +244,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
UILocalNotificationDateInterpretation.absoluteTime,
|
UILocalNotificationDateInterpretation.absoluteTime,
|
||||||
);
|
);
|
||||||
_showSnack('Alarm scheduled.');
|
_showSnack('Alarm scheduled.');
|
||||||
|
} else {
|
||||||
|
_showSnack('Platform not detected, unsure how to show alarm.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user