How to use StreamProvider with minimal widget re-build and firestore read?

477

With Provider, you can use Consumer and Selector to avoid unnecessarily rebuilds.

https://pub.dev/documentation/provider/latest/

Share:
477
leemuljadi
Author by

leemuljadi

From 'Hello World' to 'Change the World'.

Updated on December 16, 2022

Comments

  • leemuljadi
    leemuljadi over 1 year

    I want to StreamProvider to pass my UserData object through out all the widgets, so it can be accessible anywhere.

    The UserData object is taken/read from the Firestore database.

    My questions are:

    1. How can I use StreamProvider properly/efficiently so it will minimize the widget rebuild and read from Firestore (cause Firebase bills per every document read, CMIIW)?
    2. Should I use FutureProvider instead? But I want the UI also be able to be updated when there is change in the database.