I have a screen where I need to get a JSON file name from Firestore first and then load the asset JSON file. I usually use StreamBuilder for Firestore document snapshots and I can load JSON with a FutureBuilder. My question is how can I combine them? Or, is there any better way of doing what I mentioned?
As far as I know, FutureBuilder cannot work properly inside StreamBuilder, so it is not a choice I guess.
I get snapshots from Firestore as:
UserModel _userDataFromSnapshot(DocumentSnapshot snapshot) {
final userdata = snapshot.data();
return UserModel(
...
);
}
Stream<UserModel> get userData {
return userCollection.doc(uid).snapshots()
.map(_userDataFromSnapshot);
}
And I load JSON as:
FutureBuilder(
future: DefaultAssetBundle.of(context).loadString(fileName),
builder: (context, snapshot) {
if(snapshot.hasData) {
final data = json.decode(snapshot.data.toString()).cast<String, dynamic>();
...
I appreciate any help or comment.