send method
Send the push notification
Implementation
Future<void> send({DateTime? at}) async {
await NyScheduler.taskOnce('push_notification_permissions', () async {
// request permissions
await requestPermissions();
});
_sendAt = at;
NotificationDetails notificationDetails = await _getNotificationDetails();
if (_initialized == false) {
_initialized = await Nylo.instance.initializeLocalNotifications();
}
if (_sendAt != null) {
String? sendAtDateTime = at.toDateTimeString();
if (sendAtDateTime == null) {
throw Exception("Invalid date provided");
}
await Nylo.localNotifications((FlutterLocalNotificationsPlugin
flutterLocalNotificationsPlugin) async {
await flutterLocalNotificationsPlugin.zonedSchedule(
_id ?? 1,
_title,
_body,
tz.TZDateTime.parse(tz.local, sendAtDateTime),
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exact,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
payload: _payload,
);
});
return;
}
await Nylo.localNotifications((FlutterLocalNotificationsPlugin
flutterLocalNotificationsPlugin) async {
await flutterLocalNotificationsPlugin.show(
_id ?? 1,
_title,
_body,
notificationDetails,
payload: _payload,
);
});
}