【问题标题】:Read Data Firebase [duplicate]Read Data Firebase [duplicate]
【发布时间】:2022-12-02 02:11:34
【问题描述】:

I would like to recover data in my firebase database but it does not work.

void _userData() async {
    DocumentReference documentReference = FirebaseFirestore.instance
        .collection("Users")
        .doc("axelduf2006@gmail.com");
    documentReference.get().then((datasnapshot) {
      data = datasnapshot.data;
      return print("pseudo: ${data['pseudo']}");
    });
  }

my log console

I would like to know the value contained in pseudo in my database.

【问题讨论】:

  • Please don't post screenshots of your code, or other textual content (such as log console output). Instead post the actual text, and use the formatting tools of Stack Overflow to mark it up. Also see: Why not upload images of code/errors when asking a question?
  • datasnapshot.data is a method, so data = datasnapshot.data().

标签: android flutter dart google-cloud-firestore


【解决方案1】:

Change data with data() to get the Map<String, dynamic> of your document.

void _userData() async {
DocumentReference documentReference = FirebaseFirestore.instance
    .collection("Users")
    .doc("axelduf2006@gmail.com");
documentReference.get().then((datasnapshot) {
  data = datasnapshot.data() as Map<String, dynamic>; // set it like this
  return print("pseudo: ${data['pseudo']}");
});
}

Passing the data will pass the definition of Function Map&lt;String, dynamic&gt; ( () => Map<String, dynamic> ), not the actual Map&lt;String, dynamic&gt; of the document data.

【讨论】:

    猜你喜欢
    • 2016-04-18
    • 2018-05-22
    • 2021-07-29
    • 2021-11-21
    • 2017-12-29
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    相关资源
    最近更新 更多