gpt4 book ai didi

firebase - 为小部件调用两个不同端点的最佳实践?

转载 作者:IT王子 更新时间:2023-10-29 06:32:43 27 4
gpt4 key购买 nike

当需要两个不同的端点来呈现某些内容时,最佳做法是什么?现在我正在嵌套 FutureBuilders,但这似乎并不理想。

例子:

@override
Widget build(BuildContext context) {
return new FutureBuilder(
future: Firestore.instance.collection('games').document(this.documentId).get(),
builder: (BuildContext gamesContext, AsyncSnapshot gamesSnapshot) {
return new FutureBuilder(
future: Firestore.instance.collection('profiles').document(gamesSnapshot.data['authorId']).get(),
builder: (BuildContext profilesContext, AsyncSnapshot profilesSnapshot) {
// Code goes here.
}
),
}
),
}

一定有更简洁的方法,对吧?

最佳答案

您可以使用单个 FutureBuilder 执行此操作:

Future<AsyncSnapshot> getProfiles() async {
var gamesSnapshot = await Firestore.instance.collection('games').document(this.documentId).get();
return Firestore.instance.collection('profiles').document(gamesSnapshot.data['authorId']).get()
}

@override
Widget build(BuildContext context) {
return new FutureBuilder(
future: getProfiles(),
builder: (BuildContext profilesContext, AsyncSnapshot profilesSnapshot) {
// Code goes here.
}
),
}

关于firebase - 为小部件调用两个不同端点的最佳实践?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50341710/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com