updateMeal method

Future<bool> updateMeal({
  1. required Meal meal,
  2. required int userID,
})

Updates an existing meal in the database based on user, day, and meal type.

  • meal: The meal object containing updated data.
  • userID: The ID of the user who owns the meal.
  • year: The year of the meal.
  • month: The month of the meal.
  • day: The day of the meal.
  • mealType: The meal type (e.g., "breakfast", "lunch").

Returns a Future<bool> indicating if the operation was successful.

Implementation

Future<bool> updateMeal({required Meal meal, required int userID}) async {
  final int? mealID = await getMealID(userID, meal.year, meal.month, meal.day, meal.mealType);
  if (mealID == null) {
    return false; // Meal or day not found
  }

  await _databaseWrapper.ensureDBIsInitialized();

  final int count = await _databaseWrapper.database.update(
    'meals',
    meal.toMap(),
    where: 'ID = ?',
    whereArgs: [mealID],
  );

  return count > 0;
}