Home > Net >  How to Convert Dart Snapshot object data to String Variables from Flutter Firestore?
How to Convert Dart Snapshot object data to String Variables from Flutter Firestore?

Time:12-28

I am Performing CRUD operations with Flutter Firestore. Here i want to Read data from Firestore i have a Peace of code here.

      var noteInfo = snapshot.data!.docs[index].data()!;
      String docID = snapshot.data!.docs[index].id;
      print(noteInfo.toString());

here noteInfo contains Following data

{description: My Name is Qasim, title: Qasim}

Now i have two String Variables Name where i want to store title attribute of noteInfo and des where i want to store description attribute of object noteInfo. Data from Firestore is fetched. I just want to store these two attributes in seprate string variables. enter image description here

CodePudding user response:

As far as I can see in your code, noteInfo is a Map. So you can get the values for those two variables with:

var title = noteInfo["title"];
var description = noteInfo["description"]

To get the data as a map, use:

var noteInfo = snapshot.data!.docs[index].data()! as Map;

Also see: Convert Firestore DocumentSnapshot to Map in Flutter

  • Related