Firestore:在控制台中显示集合文档

Firestore: Show Collection Documents in Console

我有一个使用 firestore 数据库的 flutter 应用程序,我想在控制台中显示来自“产品”集合的数据,但我收到的是:

I/flutter ( 5747): Instance of 'Future<QuerySnapshot>'

有没有办法实现它..这是我的代码:

Future<void> getItems() async {
  final response = await Firestore.instance.collection("products").getDocuments();
  print(json.decode(json.decode(response)));
}

这应该有效:

  Future<void> getItems() async {
  final response = await Firestore.instance.collection("products").getDocuments();
  response.documents.forEach((element) {
    print(element.data);
  });
}

既然你用的是await,那么getDocuments()应该return一个QuerySnapshot,然后你就可以用documents迭代了。