addMeal method

Future<bool> addMeal({
  1. required Meal meal,
  2. required User user,
})

Adds a new meal to either the local database or the API.

  • meal: The Meal object containing the meal details to be added.
  • user: The User object representing the current user.

Returns a Future<bool> indicating whether the meal was successfully added.

Implementation

Future<bool> addMeal({required Meal meal, required User user}) async {
  if (useLocalDb) {
    // Add meal to the local database
    await _mealDatabaseRepo.addMeal(meal: meal, userID: user.ID);
    return true;
  } else {
    // Add meal via the API
    final ApiReturn apiResponse = await _apiConnector.getMealRepo().addMeal(meal: meal, user: user);
    return apiResponse.success;
  }
}