AbhishekGokavarapu
AbhishekGokavarapu

Reputation: 33

Flutter | Firebase | Unable to print the message data with print(message.data)

I am pursuing a course on Udemy on flutter development, I am a beginner trying to master flutter, In the mid-way of the course, my instructor has the below code:

  void getMessages() async {
    final messages = await _fireStore.collection('messages').get();
    for (var message in messages.docs) {
      print(message.data);
    }
  }

And I had the same code as above when executed, she was able to read the data of the messages in firestore, while I was unable to print the same message, even though the code was same, after tweaking the code, I changed my code as below, by just adding the '()' on the message.data();, Now I am also able to see the messages.

The question here is how did she get the data printed without using () on messages.data, I am a beginner, I would like to understand the logic, please.

  void getMessages() async {
    final messages = await _fireStore.collection('messages').get();
    for (var message in messages.docs) {
      print(message.data());
    }
  }

Upvotes: 3

Views: 289

Answers (1)

Migalv
Migalv

Reputation: 702

this is because, with the upgrade to FlutterFire, they changed some method declarations & getters in the Firebase libraries.

.data to data(), documents to docs , etc...

Take a look at FlutterFire, it might help you. It has all the documentation needed use Firebase with Flutter.

Upvotes: 3

Related Questions