为了呈现某些内容,需要两个不同的端点时,最佳做法是什么?现在我正在筑巢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.
}
),
}
),
}
必须采用更清洁的方式,对吧?
答案 0 :(得分:2)
您可以使用一个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.
}
),
}