问题与流和firebase坏状态:字段在DocumentSnapshotPlatform中不存在 &



我有一个StreamBuilder,它的意思是让我从firestore基于正在传递的变量的文档列表,虽然我得到上述错误。

StreamBuilder

StreamBuilder<QuerySnapshot>(
stream: DatabaseService.getFeedPosts(widget.currentUserId),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
// Loader Animation Widget
Padding(padding: const EdgeInsets.only(top: 20.0)),
Text('Finding tasks'),
],
),
);
}
if (snapshot.hasData) {
final documents = snapshot.data.docs;
return ListView(
children: documents
.map(
(doc) => TaskList(
currentUserId: widget.currentUserId,
task: doc['id'],
user: doc['ownerId'],
),
)
.toList());
} else if (snapshot.hasError) {
print('Error');
return Text('It's Error!');
}
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Unable to  find any tasks'),
],
),
);
}),

重火力点查询
static Stream<QuerySnapshot> getFeedPosts(String userId) {
return tasksRef
.where('authorId', isEqualTo: userId)
.orderBy('timestamp', descending: true)
.snapshots();
}

在使用[]运算符之前,应该先从QueryDocumentSnapshot调用data()方法:

return ListView(
children: documents
.map(
(doc) => TaskList(
currentUserId: widget.currentUserId,
task: doc.data()['id'],
user: doc.data()['ownerId'],
),
)
.toList(),
);

相关内容

  • 没有找到相关文章

最新更新