Get stream of data from DB | Sembast | Flutter

Viewed 17

I'm working with Sembast nowadays and was wondering If there's any way to create a stream of data that could get me all the values inside the DB. My requirement is to setup a listener on that stream so that whenever the data change is triggered, I could do something with it.

Documentation on Sembast is pretty limited and I'm now sure how I can do this. Usually I use the .find method to fetch all the values from within my db. I've been using a stringMapFactory to store my records.

Can we do this ? Any help would be really appreciated.

2 Answers

Sorry for the poor documentation.

It is quite similar to firestore. You can listen to all changes in a store

// Track every store changes
var query = store.query();
var subscription = query.onSnapshots(db).listen((snapshots) {
  // snapshots always contains the list of all records

  // ...
});

Basically you have a query on the store (with or without filter) that you can query or listen for changes.

If you use Hive as db, may use Hive Box as listenable.

ValueListenableBuilder<Box<YOUR_BOX_MODEL>>(
valueListenable: box.listenable(),
builder: (context,value,child){}
)
Related