我有一个stremBuilder
从firebase获取快照的快照,该快照包含一些发布信息,并且我使用它来创建Posting
类的新实例,并将此发布传递给postingPage
。
Posting
class的属性之一是上传帖子的用户的ID。
我有一个基于id提取用户的函数,但是我不知道在哪里调用它,因为它是一个Future
函数。
我需要在哪里调用此提取用户函数以获取所有用户数据postingPage
?
代码预览:
StreamBuilder<QuerySnapshot>(
stream: _stream,
builder: (
BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshots
) {
if (snapshots.hasError) {
print(snapshots.error.toString());
}
switch (snapshots.connectionState) {
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
default:
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 4
),
itemCount: snapshots.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot snapshot =
snapshots.data.documents[index];
Posting currentPosting =
posting.getPostingData(snapshot);
return InkWell(
onTap: () {
// Navigator.of(context)
// .pushNamed(ViewPostingScrenn.routeName);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ViewPostingScrenn(
posting: currentPosting,
),
),
);
},
child: PostingGridTile()
);
},
);
}
},
),
您可以将期货链接为网络获取并使用,FutureBuilder
而不是StreamBuilder
在窗口小部件中使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句