i am working on a flutter project for android mobile that essentially gives periodic reminders on a specified schedule, and while my print statements for debugging say that the notification should have been scheduled, and while I know for a fact that my app can send push notifications, for some reason that i haven’t found yet, these scheduled notifications just don’t get delivered.
console after scheduling:
I/flutter (11356): Scheduling notification for abc at 2024-07-14 12:58:46.199693-0700
I/flutter (11356): Notification scheduled successfully
notifications.dart file:
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:timezone/timezone.dart' as tz;
import 'main.dart';
Future<void> scheduleNotification(String medName, String interval) async {
try {
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails(
'medication_channel',
'Medication Reminders',
channelDescription: 'Channel for medication reminders',
importance: Importance.defaultImportance,
);
const NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
final parts = interval.split(':');
final hours = int.parse(parts[0]);
final minutes = int.parse(parts[1]);
final now = tz.TZDateTime.now(tz.local);
final nextTime = now.add(Duration(hours: hours, minutes: minutes));
print('Scheduling notification for $medName at $nextTime');
await flutterLocalNotificationsPlugin.periodicallyShowWithDuration(
0,
'Medication Reminder',
'Time to take $medName',
Duration(hours: hours, minutes: minutes),
platformChannelSpecifics,
androidScheduleMode: AndroidScheduleMode.alarmClock,
);
print('Notification scheduled successfully');
} catch (e) {
print('Error scheduling notification: $e');
}
}
once the name of the reminder and the specified duration are added in, I was expecting them to repeatedly be triggered at the interval specified by the duration, but instead even though it says that the notification schedule was added in console, it never happens`
SavPass9 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1