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.
Asked
Active
Viewed 5,244 times
13

Rehmat Singh Gill
- 551
- 1
- 6
- 15
-
2use https://pub.dev/packages/moor, it says: *"Reactive: Turn any sql query into an auto-updating stream! This includes complex queries across many tables"* – pskink Jul 27 '20 at 06:43
-
Thanks @pskink, can you please show me how to do it. I could not get it from their docs. – Rehmat Singh Gill Jul 27 '20 at 06:46
-
see `SimpleSelectStatement` official documentation – pskink Jul 27 '20 at 06:49
4 Answers
2
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).

Raheem
- 524
- 1
- 7
- 18
0
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.

Omatt
- 8,564
- 2
- 42
- 144