-1

I want to use firebase snapshot doc changes and when doc change get popup screen. im using mvvp architecture with riverpod. how can i implement it repository and show in my relevant screen? 1 . repository --- 2. ModelView --- 3. screen( homeview with return autotab router.) currently what i doing is call getorder inside widget and call popup inside modified field.

this is my repository. 

class OrderOnSnap {
  final Reader read;
  OrderOnSnap(
    this.read,
  );

  late final _firestore = read(firestoreProvider);
  getOrders(uid) async {
    _firestore.collection("orders_ready").snapshots().listen((result) {
      for (var res in result.docChanges) {
        if (res.type == DocumentChangeType.added) {
          //print("added");
          //print(res.doc.data());
        } else if (res.type == DocumentChangeType.modified) {
          print("modified");
          final abc = res.doc.data();

          final status = abc!['orderPickup'];

          if (status == '2') {
            print('new order received');
            popupscreen(){};
          }
        } else if (res.type == DocumentChangeType.removed) {
          print("removed");
        }
      }
    });
  }

  
}

1 Answers1

0

The firebase event is an external event that your application receives and it is interpreted in order to execute an action. From this perspective it is just like an event that a GUI sends. You need a very similar code structure. You have a listener that listens to the event, code that interpretes it and triggers an action on the presenter (or the controller in mvc). The presenter can then call an interactor or in your case just update the model and tell the 'popup' view to open.

René Link
  • 48,224
  • 13
  • 108
  • 140