1
votes

My data is stored in nested form like

Collection->Document->Collection->Document->Collection->Document

I am fetching data using stream builder in flutter. My aim is to create an instance of a class whose attributes are distributed in all the three layers of collection/documents.

After reading second layer, my function return the class object having partial values null, and shows the error on screen, but after some time it prints the values in the last layer.

I can not use the async/ await functionality here because of the stream builder.

I tried to make the nested function but no again.

I have tried sleep() function as well.

As you can below, After reading productVariant Snapshots, it skips the foreach loop and creates an instance of Order and return. However I'm also printing the values and they got print after the return command execute.

Code Snippet

1
I'm not offering an answer, but a recommendation, don't do the fetching in the UI! try (at least) to follow clean code , also providing a copy pastable snippet will help people to help you - Francesco Iapicca

1 Answers

1
votes

Thanks for the answers, but I figured out the solution.

I used the nested FutureBuilders which returns promised widgets.

I modified my Order instance by updating variables with widgets.

Before

StreamBuilder -> Fetching Collections and Documents

After

StreamBuilder -> FutureBuilder to Fetch Collection/Document ->FutureBuilder - >To fetch inner Collection/Document