1

I have created my own PHP api for getting and deleting data from database but I want realtime change like firestore database. So how can I listen for data changes in MySQL database? I know stream is the way but how to apply it in Flutter App.

3
  • Hi, did you find a solution for this yet? Commented Jun 13, 2022 at 1:23
  • @Texv Not yet, I tried to switch to firebase. Commented Jun 14, 2022 at 7:41
  • Very interesting question. I'm wondering the same thing. I think part of the problem is how to listen for MySQL changes (and signal them to PHP) which is asked here: stackoverflow.com/questions/74510554/… Commented Oct 16, 2023 at 4:47

2 Answers 2

1

Use a replication library and connect to the mysql server as a slave.

This will give you a feed of all database chagnes.

Sign up to request clarification or add additional context in comments.

3 Comments

The library you are suggesting is performing action in every second as I seen by given link on GitHub Readme.md file. That I can do myself but I want realtime changes.
Apologies, I was assuming it was a realtime replication library like github.com/noplay/python-mysql-replication . I also didn't requite realize it was so new. I'll let you search for a php equivalent or move using to using python (recommended for improving coding anyway).
Thanks for your recommendation @danblack. I will definitely give it a try on some other day because I am working for a client project right now and I don't have knowledge of python. It will be appreciated if any solution for MySQL DB via PHP.
0

When i wanted to do a similar thing i created a function that gets the data from database then used a timer to call the function every 3 seconds. After every three seconds the updated ui is rebuilt.

Dont forget to check if the page is mounted and also to dispose the timer

This is What i did

Timer timer = Timer.periodic(const Duration(seconds: 3), (timer) {
  setState(() {
    refreshProductQuantity();
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.