I'm developing a project in Flutter for the first time and am trying to find the best way to organize my Firestore DB. I believe I have it the way I want it but can't figure out how to query it correctly.
I have a user with an ID to a collection that associates a player profile to their user profile (in separate collections).
I need to:
- grab the Firebase currentUser uid
- find the associated player profile
- Get the event IDs saved to the player profile
- list of events based on their IDs
I'm guessing in that order.
DatabaseReference getCurrentUserRef() async {
return this.usersRef.child((await this.getCurrentUser()).uid);
}
var user = await getCurrentUserRef()
var _playerEvents = [];
db.collection('player').where('id', isEqualto: user).get().then((doc) => {
db.collection('player').doc(doc.data().id).collection('events').get().then((snapshot) => {
snapshot.forEach(doc) {
_playerEvents.push(doc.data().id);
}
});
});
Then with that array i need to get all the events based on those id (if there are any)
_playerEvents.forEach(event) {
db.collection('events').where('id', isEqualTo: event).get().then((doc) => {
//somehow popular a Map or JSON that I can show in a list view on the page for the events associated with that player
List_Item for display
});
}
Here are some screens to my DB. I am learning Flutter which uses dart. Any help would be amazing.