send method

Future<void> send({
  1. DateTime? at,
  2. AndroidScheduleMode? androidScheduleMode,
})

Sends the notification.

If at is specified, the notification will be scheduled for that time. Otherwise, it will be shown immediately.

Implementation

Future<void> send({
  DateTime? at,
  AndroidScheduleMode? androidScheduleMode,
}) async {
  _assertNotWeb();

  await NyScheduler.taskOnce('local_notification_permissions', () async {
    await requestPermissions();
  });

  _sendAt = at;

  final notificationDetails = await _getNotificationDetails();

  if (!_initialized) {
    _initialized =
        await Nylo.instance.initializeLocalNotifications() ?? false;
  }

  if (_sendAt != null) {
    await _sendScheduledNotification(
      notificationDetails,
      androidScheduleMode ?? AndroidScheduleMode.exactAllowWhileIdle,
    );
    return;
  }

  await _sendImmediateNotification(notificationDetails);
}