I have a fully functional app created in Flutter. It uses sqflite plugin for storing data. I want to have a data change listener, which will update or refresh the data when new data is added or updated. How can I achieve this. I came across a sqflite helper plugin sqlcool but could not figure out a way to use it with my existing database in sqflite. Please help me.
Thanks.
I also faced the same problem as yours, and ended up using Drift (Moor).
You can learn about it from its documentation -> https://drift.simonbinder.eu/docs/getting-started/
It's has similar features as Jetpack Room in Native Android Development. It also notifies when database changes using Flutter Stream API which you can easily observe (subscribe).
You can achieve similar function of listening to sqflite changes by implementing Streams, adapting BloC pattern. You can check this blog post for a sample. One way of achieving this is by updating the Stream paired to sqflite. With this approach, you can use StreamBuilders that can automatically rebuild child widgets when there's change on Stream.
You can add stream to your data fetching function.
You can learn more about flutter streams from this link .
Consider this sqlbrite package, it will allow you to listen to sqlite changes as a stream.
© 2022 - 2025 — McMap. All rights reserved.
SimpleSelectStatement
official documentation – Hedgehop