Listen to real-time changes in Flutter SQFLite Database
Asked Answered
D

4

14

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.

Dominik answered 27/7, 2020 at 6:35 Comment(3)
use pub.dev/packages/moor, it says: "Reactive: Turn any sql query into an auto-updating stream! This includes complex queries across many tables"Hedgehop
Thanks @pskink, can you please show me how to do it. I could not get it from their docs.Dominik
see SimpleSelectStatement official documentationHedgehop
A
3

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).

Amazed answered 25/8, 2022 at 14:45 Comment(0)
H
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.

Hemi answered 14/2, 2022 at 7:29 Comment(0)
R
0

You can add stream to your data fetching function.

You can learn more about flutter streams from this link .

Ribald answered 23/8, 2022 at 9:34 Comment(0)
A
0

Consider this sqlbrite package, it will allow you to listen to sqlite changes as a stream.

Absolutely answered 1/11, 2022 at 11:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.