Firebase use as a backend for Flutter

Flutter : Firebase use as a backend


Firebase provided two types of database first cloud firestore and Realtime database.
Both have their limitation.


First, we know about listener for firebase data in Flutter.

getUserTask()  {
   Firestore.instance      .collection('tasks')
      .where("assignedTo", isEqualTo: " JVgonhjkjpWnvf8taBNL")
      .snapshots()
      .listen((event) {
    event.documentChanges.forEach((document) {
      print("value number 2 : ${document.document.data}");    });  });}

In the above method, A query and at the end-use snapshots then listen then get the data.
This query only listens the whatever change will happen in the tasks collection.

In the second picture, you just get the data once and not able to listen to the real-time changes you need to restart the state.

 
getFoods() async {
  QuerySnapshot snapshot = await Firestore.instance      .collection('tasks')
      .where("assignedTo", isEqualTo: " JVgonhjkjpWnvf8taBNL")
      .getDocuments();
  List<Tasks> _foodList = [];
  snapshot.documents.forEach((document) {
    print("value number 2 : ${document.data}");    Tasks food = Tasks.fromMap(document.data);    _foodList.add(food);  });  print("value : $_foodList");}

Comments

Post a Comment