What is considered the best practice to use when two different endpoints are needed in order to render something? Right now I'm nesting FutureBuilders but that doesn't seem ideal.
Example:
@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.
}
),
}
),
}
There's got to be a cleaner way, right?
You can do this with a single 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.
}
),
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments