1

I will build an app where I fetch data from http. The backend is PHP and on the page it show me the phpmyadim database.

In flutter I would like to get the data and show it in a listview. And when the data is change I would like that the listview is automatically reloaded.

My question is should I use Future builder or stream builder? And how I should do it.

easeccy
  • 4,248
  • 1
  • 21
  • 37
Berkkan
  • 97
  • 1
  • 4
  • 8

2 Answers2

3

WebSockets is a good choise when your data changes very frequently for example during chat session. Otherwise I propose to use Firebase Cloud Messaging it will give you online data update when your app is open and push notification if it's close.

In your root widget

  final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();

  @override
  void initState() {

    super.initState();

    _firebaseMessaging.configure(
        onMessage: (Map<String, dynamic> message) async {
           // or use setState
          _bloc.dispatch(new LoadMyCalendar());
        }
    );

Second part is call Firebase API from your web server app when data is changing

Ilya Sulimanov
  • 7,636
  • 6
  • 47
  • 68
  • We use this and it works really well for iOS, Android, Web, Flutter. Also you can turn off push notifications optionally. – Oliver Dixon Jul 10 '20 at 14:23
2

You can't update the data in realtime with HTTP requests. Only sockets can allow realtime comunication. You need to use websocket in this case. These might help:

Websockets in PHP

Websockets in Flutter

easeccy
  • 4,248
  • 1
  • 21
  • 37