1

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 Commented Nov 18, 2020 at 9:38

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.