How to fetch nested documents using streambuilder from Firestone in flutter?

221

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

Share:
221
Shoaib Aslam
Author by

Shoaib Aslam

Updated on November 27, 2022

Comments

  • Shoaib Aslam
    Shoaib Aslam over 1 year

    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

    • Francesco Iapicca
      Francesco Iapicca over 3 years
      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