0

I have a flutter app that uses flask as backend and when ever some data changes in the backend, I want to send an Alert Dialog to user. Although I know how to use Alert Box, I'm confused where the code for it should be placed as I'm using 3 screens and navigating then via PageView.

My use case is that I have a PIR sensor equipped onto a raspberry pi and when ever motion is detected, motion_status value turns to true and sends to flutter app via flask app.

I'm confused about where i need to place the Alert Dialog widget so that when ever movement happens, no matter what screen i'm in i should get alert box .

Vasudeva S
  • 125
  • 2
  • 11
  • Do you know how to contact and let the flutter app know when the change happened in the backend – Ridha Rezzag Jun 13 '22 at 14:50
  • I'm using http package to get the data from raspberry pi and then decoding it. Later I'm using provider to handle the state and fill values into text widget that updates dynamically – Vasudeva S Jun 13 '22 at 14:55
  • One more question before I write an answer for you, how many flutter apps you want to notify about the change, is it just one app or multiple apps and is the notification specific to one person, or it's a general for everyone that installed the app? – Ridha Rezzag Jun 13 '22 at 15:37
  • It is just one app that i want to notify about the change and is notification sent is user specific. I.e. if the user has the hardware device and if it is turned on then only it should notify the user – Vasudeva S Jun 13 '22 at 16:12

1 Answers1

0

So when an update happen in the backend, you have couple different ways to get the app notified about the change just happened,

1- first you create a stream in the flutter app calling the server to check if any change happened, that stream reoccurs every few minutes or seconds, but that's not a good solution because there will be a lot of calls to the server and the info won't be instant.

2- use a web socket system

Best solution

3- use FCM Firebase cloud messaging system, whenever a change happened in the backend you write a code that calls Firebase account associated with your flutter app and your Firebase account will send a notification with data load to your app, when your app receives that real time notification you can then show to the user the alert dialog

Ridha Rezzag
  • 3,672
  • 1
  • 34
  • 39