You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/ai_recipe_generation/lib/features/recipes/recipes_view_model.dart

32 lines
807 B

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import '../../services/firestore.dart';
import 'recipe_model.dart';
class SavedRecipesViewModel extends ChangeNotifier {
List<Recipe> recipes = [];
final recipePath = '/recipes';
final firestore = FirebaseFirestore.instance;
SavedRecipesViewModel() {
firestore.collection(recipePath).snapshots().listen((querySnapshot) {
recipes = querySnapshot.docs.map((doc) {
final data = doc.data();
return Recipe.fromFirestore(data);
}).toList();
notifyListeners();
});
}
void deleteRecipe(Recipe recipe) {
FirestoreService.deleteRecipe(recipe);
}
void updateRecipe(Recipe recipe) {
FirestoreService.updateRecipe(recipe);
notifyListeners();
}
}