mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Adds ai_recipe_generation sample (#2242)
Adding the demo app from my I/O talk. Because AI. ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. --------- Co-authored-by: Brett Morgan <brett.morgan@gmail.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user