Combine two stream-queries in flutter

325 views Asked by At

I want to create a streambuilder to download multiple user-profiles from firebase. But to know which users are needed I have to get the user-ids at first, these are stored in an array. So I created a method to download the array and after this is done the streambuilder loads the user-data for each user-id from the array. Here's the code:

Method to get the array (executed in initState()):

Stream<QuerySnapshot> stream() async* {
job = Job.fromJson(await FirebaseFirestore.instance
    .collection("jobs")
    .doc(widget.jobId)
    .get());
applicants = job.applicants;
await FirebaseFirestore.instance
    .collection('users')
    .where('uid', whereIn: applicants)
    .snapshots();
}

And the streambuilder in the scaffolds' body:

body: isLoading
      ? Center(child: Container(child: CircularProgressIndicator()))
      : applicants.isEmpty
          ? Center(
              child: Text("no values"),
            )
          : StreamBuilder<QuerySnapshot>(
              stream: stream(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Center(child: CircularProgressIndicator());
                } else { xy }

So my question is if there's a possibility to combine the first method and the stream. Because at the moment the user can't get any update if an application is withdrawn while using the screen.

0

There are 0 answers