【发布时间】:2022-01-22 08:34:10
【问题描述】:
好的,所以基本上我有这个项目,我想为我的应用程序创建一个数据库,所以我像往常一样在我的项目中添加了 firebase,我创建了我的 database_service 文件,但如果 somoene 可以帮助我会出现这个错误像往常一样非常伟大。
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:have_to/model/todo.dart';
class DatabaseService{
CollectionReference todosCollection = FirebaseFirestore.instance.collection("Todos");
Future createNewTodo(String title) async{
return await todosCollection.add({
"title":title,
"isComplet":false,
});
}
Future completTask(uid)async{
await todosCollection.doc(uid).update({"isComplet":true});
}
List<Todo>? todoFromFirestore(QuerySnapshot snapshot){
if(snapshot != null){
snapshot.docs.map((e) {
return Todo(uid: e.id,
title: (e()["title"]),
isComplet: e()["isComplet"],);
}).toList();
}else{
return null;
}
}
Stream<List<Todo>> listTodos() {
return todosCollection.snapshots().map(todoFromFirestore);
}
}
【问题讨论】:
标签: firebase flutter android-studio google-cloud-firestore