Home > Net >  Is it recommended to use Stream Builder for a single data fetched from a database? if so, will it hi
Is it recommended to use Stream Builder for a single data fetched from a database? if so, will it hi

Time:08-29

Is there any problem using StreamBuilder for a single set of data that is fetched from database in my app?

CodePudding user response:

Stream builder is to continuously get data. Even if its a single data or multiple entries if the app needs to fetch data continuously then its good to use Stream builder. Btw fetching single entry will not affect the performance of the app to a great extent. So you should be good to go with Stream builder

https://api.flutter.dev/flutter/widgets/StreamBuilder-class.html

CodePudding user response:

In general terms, no, it is not a problem nor does it greatly effect the performance of the app.

But as always, it depends on more factors. Let for instance say you have a ListView with a bunch of Card in it. And in each Card you have 10 Text-widgets. If you now have a StreamBuilder for each of those Text-widget, and each StreamBuilder does separate requests to your database, and each query is timeconsuming... then yes; it is not optimal. But if it in the end will effect the performance is still hard to say. You'd have to test :) Don't optimize before you need to.

  • Related