Click here to Skip to main content
15,885,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have built a streambuilder that has two-page builders. I realized it is not iterating over the last if statement, does anyone knows a function so that I can get it to iterate over the last if statement too?

The condition of all if statements are being met

My widget:
StreamBuilder2<QuerySnapshot<Map<String, dynamic>>,
              QuerySnapshot<Map<String, dynamic>>>(
          streams: Tuple2(stream1, stream2),
          builder: (ctx, snapshots) {
            if (!snapshots.item1.hasData && !snapshots.item2.hasData) {
              return const Center(
                child: CircularProgressIndicator(),
              );
            }
            if (snapshots.item1.hasData) {
              return PageView.builder(
                  itemCount: snapshots.item1.data!.docs.length,
                  itemBuilder: ((context, index) {
                    INvideoPlayerController = VideoPlayerController.network(
                      snapshots.item1.data!.docs[index].get('url'),
                    )
                      ..setLooping(true)
                      ..initialize()
                          .then((value) => INvideoPlayerController!.play());
                    return AspectRatio(
                      aspectRatio: INvideoPlayerController!.value.aspectRatio,
                      child: VideoPlayer(INvideoPlayerController!),
                    );
                  }));
            }

            if (snapshots.item2.hasData ) {
              return PageView.builder(
                  itemCount: snapshots.item2.data!.docs.length,
                  itemBuilder: ((context, index) {
                    return FittedBox(
                      child: Container(
                        margin: const EdgeInsets.all(7),
                        child: FadeInImage.memoryNetwork(
                            fit: BoxFit.cover,
                            placeholder: kTransparentImage,
                            image:
                                snapshots.item2.data!.docs[index].get('url')),
                      ),
                    );
                  }));
            }
            return Text('done');
          }),


What I have tried:

I tried using one-page builder but I was getting the same problem that I was not able to exit the 2nd if loop even after the data was not present in it which gave range errors.

I cannot find a solution on the net on how to make it iterate over another loop.
Posted
Comments
wseng 19-Feb-22 0:29am    
you mean if snapshots.item2 has data, it still run on first if-else?
Kavya Bhargava 19-Feb-22 4:44am    
yes right, also if I make snapshots.item2 the first statement then it will iterate over it but not snapshots.item1, either way not iterating over second if
wseng 19-Feb-22 6:28am    
then you should do like this:

if(snapshots.item2.hasData && !snapshots.item1.hasData)
Kavya Bhargava 19-Feb-22 12:46pm    
Tried this , nothing changed
wseng 20-Feb-22 1:12am    
because snapshots.item2 and snapshots.item1 always has data,that's why nothing is changed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900