【问题标题】:Firebase: How to fetch data from an array field and print it in console?Firebase:如何从数组字段中获取数据并在控制台中打印?
【发布时间】:2022-12-16 21:11:16
【问题描述】:

几乎我看过和读过的所有教程和文章总是会导致像 Streambuilder 或 Futurebuilder 这样复杂的东西。我只想从控制台的数组字段中打印数据。没有什么特别的。

我想在这里获取这些数据。

【问题讨论】:

    标签: flutter firebase google-cloud-firestore


    【解决方案1】:

    要获取数据,请执行以下操作:

    final doc = await FirebaseFirestore.instance.doc('goals/7L3n...').get();
    final data = (doc.data()) as Map<String, dynamic>;
    for (final photo in data['photos'] as List<String>) {
      print(photo);
    }
    print(data['photos'][0]); // should print (https://www...)
    print(data['photos'][1]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 2018-04-28
      相关资源
      最近更新 更多