deleteUser method

Future<void> deleteUser(
  1. BuildContext context
)

Delete the authenticated user's account @param context The BuildContext to show snack bars Returns snack bar messages based on success or failure

Implementation

Future<void> deleteUser(BuildContext context) async {
  final localizations = AppLocalizations.of(context)!;
  try {
    final userId = _authRepo.getUserID;
    if (userId.isNotEmpty) {
      await _userRepo.deleteUser(userId);
      user.value = null; // Clear global state
      Helper.successSnackBar(
          title: localizations.tCongratulations, message: 'Account has been deleted!');
    } else {
      Helper.warningSnackBar(
          title: 'Error', message: 'User cannot be deleted!');
    }
  } catch (e) {
    Helper.errorSnackBar(title: 'Error', message: e.toString());
  }
}