【发布时间】:2020-01-05 10:20:55
【问题描述】:
我有一个 stremBuilder 从 firebase 获取快照,该快照包含一些帖子信息,我使用它来创建 Posting 类的新实例,并将此帖子传递给 postingPage。
Posting 类的属性之一是上传帖子的用户的 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()
);
},
);
}
},
),
【问题讨论】:
-
asyncMap 也许?