scheduleNotification method
Future<bool>
scheduleNotification({
- required int id,
- required String title,
- required String message,
- required int scheduledEpochMillis,
- String? channelId,
- NotificationImportance? importance,
- bool alarmSound = false,
- String? targetScreen,
- Map<
String, dynamic> ? extraData,
override
Schedule a notification to be delivered by the operating system at a specific point in time, even when the app is fully closed.
Implementation
@override
Future<bool> scheduleNotification({
required int id,
required String title,
required String message,
required int scheduledEpochMillis,
String? channelId,
NotificationImportance? importance,
bool alarmSound = false,
String? targetScreen,
Map<String, dynamic>? extraData,
}) async {
try {
_scheduledTimers[id]?.cancel();
final delay =
scheduledEpochMillis - DateTime.now().millisecondsSinceEpoch;
if (delay <= 0) {
// Deliver immediately if the time has already passed.
if (web.Notification.permission == 'granted') {
web.Notification(title, web.NotificationOptions(body: message));
}
return true;
}
_scheduledTimers[id] = Timer(Duration(milliseconds: delay), () {
if (web.Notification.permission == 'granted') {
web.Notification(title, web.NotificationOptions(body: message));
}
_scheduledTimers.remove(id);
});
return true;
} catch (_) {
return false;
}
}