scheduleAllNotifications method

Future<void> scheduleAllNotifications(
  1. BuildContext context
)

Método para todas las notificaciones configuradas por el usuario.

Este método revisa las preferencias de notificación activadas y agenda cada una para su ejecución futura. Si las notificaciones están desactivadas globalmente (isActive == false), no se agenda nada.

Las notificaciones que se pueden programar son:

  • Notificación diaria: Todos los días a las 9:00 AM.
  • Motivación semanal: Cada lunes a las 9:00 AM.
  • Recordatorio de entrenamiento: Todos los días a las 18:00.
  • Notificación por inactividad: Todos los días a las 20:00.

Parámetros:

  • context: El BuildContext necesario para mostrar notificaciones.

Implementation

Future<void> scheduleAllNotifications(BuildContext context) async {
  // SI LAS NOTIFICACIONES ESTAN DESACTIVADAS EN GENERAL, NO HACEMOS NADA
  if (!isActive) return;

  // FUNCION AUXILIAR QUE CALCULA LA PROXIMA HORA PROGRAMADA (MAÑANA SI YA PASO)
  DateTime nextTimeAt(int hour, int minute) {
    final now = DateTime.now();
    var scheduled = DateTime(now.year, now.month, now.day, hour, minute);
    if (scheduled.isBefore(now)) {
      scheduled = scheduled.add(const Duration(days: 1));
    }
    return scheduled;
  }

  if (dailyNotifications) {
    await NotificationService.showNotificationSchedule(
      context,
      1,
      "daily_notifications",
      nextTimeAt(9, 0),
    );
  } // NOTIFICACION DIARIA A LAS 9:00 AM

  if (weeklyMotivation) {
    final now = DateTime.now();
    final nextMonday = now.add(Duration(days: (8 - now.weekday) % 7));
    final mondayAt9 =
        DateTime(nextMonday.year, nextMonday.month, nextMonday.day, 9, 0);
    await NotificationService.showNotificationSchedule(
      context,
      2,
      "weekly_motivation",
      mondayAt9,
    );
  } // NOTIFICACION DE MOTIVACION SEMANAL, CADA LUNES A LAS 9:00 AM

  if (trainingReminders) {
    await NotificationService.showNotificationSchedule(
      context,
      3,
      "training_reminders",
      nextTimeAt(18, 0),
    );
  } // RECORDATORIO DE ENTRENAMIENTO A LAS 18:00

  if (inactivityNotification) {
    await NotificationService.showNotificationSchedule(
      context,
      4,
      "inactivity_notification",
      nextTimeAt(20, 0),
    );
  } // NOTIFICACION DE INACTIVIDAD A LAS 20:00
}