Flutter Firestore:未为 class 'Object?' 定义运算符“[]”。 - 'Object' 来自 'dart:core'
Flutter Firestore: The operator '[]' isn't defined for the class 'Object?'. - 'Object' is from 'dart:core'
我尝试了很多方法,但一直显示错误:
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(),
);
这是我的错误,正确的解决方案是:
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(),
我尝试了很多方法,但一直显示错误:
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(),
);
这是我的错误,正确的解决方案是:
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(),