Dayman Hoffmann
Dayman Hoffmann

Reputation: 1

How to force the flutter app to request new data from the server?

I have an app made in flutter that requests data from a rest api. Currently, every time the app starts, it requests new data from the server. It also does that every 5 minutes.

I would like to know if there is any way to tell all apps from the server to request new data.

The purpose of this system is to avoid polling every 5 minutes and have information in the app almost instantly.

One way that occurred to me is to send a push notification indicating that there is new data. But I don't know how to do this. There are examples for sending notifications using firebase, but I am not using that service.

I also thought about web sockets but I think it is very expensive to maintain an open connection between the app and the server.

Any hold will be eternally grateful

Upvotes: 0

Views: 610

Answers (1)

Erika Valdes
Erika Valdes

Reputation: 66

I recommend you to use Firebase Cloud Messaging & Firebase Functions:

Firebase Functions could expose an HTTP Event https://firebase.google.com/docs/functions/http-events

This event can send a push notification to the App and then you could listen to request new data

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/example/lib/main.dart

Upvotes: 1

Related Questions