changeValue method

void changeValue(
  1. String key,
  2. bool value
)

Método que modifica un valor específico de configuración de notificación.

Este método permite modificar una opción concreta de notificación, actualizando el objeto AppNotification, guardando el cambio en SharedPreferences, y notificando a los listeners.

Parámetros:

  • key: Clave que representa el nombre del campo a modificar.
  • value: Nuevo valor booleano que se desea asignar.

Implementation

void changeValue(String key, bool value) async {
  final prefs = AppNotification.preferences;

  switch (key) {
    case 'isActive':
      notification = AppNotification(
        isActive: value,
        dailyNotifications: notification.dailyNotifications,
        weeklyMotivation: notification.weeklyMotivation,
        newRecordNotification: notification.newRecordNotification,
        trainingReminders: notification.trainingReminders,
        inactivityNotification: notification.inactivityNotification,
      );
      break;
    case 'dailyNotifications':
      notification = AppNotification(
        isActive: notification.isActive,
        dailyNotifications: value,
        weeklyMotivation: notification.weeklyMotivation,
        newRecordNotification: notification.newRecordNotification,
        trainingReminders: notification.trainingReminders,
        inactivityNotification: notification.inactivityNotification,
      );
      break;
    case 'weeklyMotivation':
      notification = AppNotification(
        isActive: notification.isActive,
        dailyNotifications: notification.dailyNotifications,
        weeklyMotivation: value,
        newRecordNotification: notification.newRecordNotification,
        trainingReminders: notification.trainingReminders,
        inactivityNotification: notification.inactivityNotification,
      );
      break;
    case 'newRecordNotification':
      notification = AppNotification(
        isActive: notification.isActive,
        dailyNotifications: notification.dailyNotifications,
        weeklyMotivation: notification.weeklyMotivation,
        newRecordNotification: value,
        trainingReminders: notification.trainingReminders,
        inactivityNotification: notification.inactivityNotification,
      );
      break;
    case 'trainingReminders':
      notification = AppNotification(
        isActive: notification.isActive,
        dailyNotifications: notification.dailyNotifications,
        weeklyMotivation: notification.weeklyMotivation,
        newRecordNotification: notification.newRecordNotification,
        trainingReminders: value,
        inactivityNotification: notification.inactivityNotification,
      );
      break;
    case 'inactivityNotification':
      notification = AppNotification(
        isActive: notification.isActive,
        dailyNotifications: notification.dailyNotifications,
        weeklyMotivation: notification.weeklyMotivation,
        newRecordNotification: notification.newRecordNotification,
        trainingReminders: notification.trainingReminders,
        inactivityNotification: value,
      );
      break;
  }

  await notification.saveToPreferences(prefs);
  notifyListeners();
}