【问题标题】:Flutter Firestore: The operator '[]' isn't defined for the class 'Object?'. - 'Object' is from 'dart:core'Flutter Firestore:未为类“Object?”定义运算符“[]”。 - “对象”来自“飞镖:核心”
【发布时间】:2022-01-22 15:12:24
【问题描述】:

我尝试了很多东西,但它一直显示错误:

children: snapshot.data!.docs.map((document) {
                final data = document.data()! as Map<String, dynamic>;
                print(data);
                return ProductCard(
                  title: Text(data["name"]),
                  imageUrl: document.data()['images'][0],
                  price: "\$${document.data()['price']}",
                  productId: document.id, onPressed: (){},
                );
              }).toList(),
            );

【问题讨论】:

标签: flutter google-cloud-firestore product


【解决方案1】:

这是我的错误,正确的解决方案是:

children: snapshot.data!.docs.map((document) {
                final data = document.data()! as Map<String, dynamic>;
                print(data);
                return ProductCard(
                  title: "${data["name"]}",
                  imageUrl: data['images'][0],
                 // price: "\$${data['price']}",
                  productId: document.id, onPressed: (){},
                );
              }).toList(),

【讨论】:

    猜你喜欢
    • 2021-09-10
    • 1970-01-01
    • 2021-07-15
    • 2021-08-26
    • 2020-05-31
    • 2021-07-30
    • 2021-08-08
    相关资源
    最近更新 更多