updatePreferences method

void updatePreferences({
  1. bool? allowEmail,
  2. bool? allowAppNotifications,
  3. bool? allowWhatsapp,
  4. bool? allowTelegram,
})

Implementation

void updatePreferences({
  bool? allowEmail,
  bool? allowAppNotifications,
  bool? allowWhatsapp,
  bool? allowTelegram,
}) async {
  try {
    final response = await Requests.getDio().put(
      '/users/config/notifications',
      data: {
        'allowEmailNotification': allowEmail ??
            (authenticationController.userConfig?.allowEmailNotification ??
                false),
        'allowAppNotification': allowAppNotifications ??
            (authenticationController.userConfig?.allowAppNotification ??
                false),
        'allowWhatsappNotification': allowWhatsapp ??
            (authenticationController.userConfig?.allowWhatsappNotification ??
                false),
        'allowTelegramNotification': allowTelegram ??
            (authenticationController.userConfig?.allowTelegramNotification ??
                false),
      },
    );

    if (response.statusCode == 200) {
      await authenticationController.getUserProfile();
      // await homeController.getNotifications();
      // DefaultSnackbar.show("Success", "Updated preferences successfully");
    } else {
      log('Error updating preferences : ${response.data}');
      CustomFlashWidget.showFlashMessage(
        type: FlashType.error,
        title: "Error",
        message: response.data?['message'] ?? "Error updating preferences",
      );
      // DefaultSnackbar.show("Error", response.data?['message'] ?? "Error updating preferences");
    }
  } catch (_) {
    log('Error updating preferences: ${_.toString()}');
    CustomFlashWidget.showFlashMessage(
      type: FlashType.error,
      title: "Error",
      message: "Error updating preferences",
    );
    // DefaultSnackbar.show("Error", "Error updating preferences");
  }
}