【发布时间】:2021-11-09 15:03:49
【问题描述】:
我在项目中更新了 Cloud Firestore 依赖项,但出现了旧代码。
错误:
没有为“对象”类型定义运算符“[]”。?
model.dart
Product.fromSnapshot(DocumentSnapshot snapshot){
_featured = snapshot.data()[FEATURED];//error occurs here
_brand = snapshot.data()[BRAND];//error occurs here
_category = snapshot.data()[CATEGORY];//error occurs here
}
update.dart
FutureBuilder<QuerySnapshot>(future: FirebaseFirestore.instance.
collection("items").where("shortInfo",whereIn: snapshots.
data.docs[index].data()[EcommerceApp.productID]).
get(),//occure error
builder: (c,snap)
{
return snap.hasData?AdminOrderCard(
itemCount: snap.data.docs.length,
data:snap.data.docs,
orderId: snapshots.data.docs[index].id,
orderBy:snapshots.data.docs[index].data()["orderBy"],//occure error
addressID:snapshots.data.docs[index].data()
["addressID"],//occure error
)
:Center(child: circularProgress(),);
},
);
List<DropdownMenuItem<String>> getCategoriesDropdown(){
List<DropdownMenuItem<String>> items = new List();
for(int i = 0; i < categories.length; i++){
setState(() {
print(i);
items.insert(0, DropdownMenuItem(child: Text(categories[i].data()['category']),
value: categories[i].data()['category']));
});
}
return items;
}
_currentCategory = categories[0].data()['category']; //The operator '[]' isn't defined for the type 'Object'. (Documentation)
pro.dart:
Future<void> getMobileandTabIconData() async {
List<CategoryIcon> newList = [];
QuerySnapshot dressSnapShot = await FirebaseFirestore.instance
.collection("categoryicon")
.doc("MhZyArOf2zrOmPO7R3y6")
.collection("mobile&tablets")
.get();
dressSnapShot.docs.forEach(
(element) {
mobileandtabiconData = CategoryIcon(image: element.data()["image"]);//error occure
newList.add(mobileandtabiconData);
},
);
mobileandtabIcon = newList;
notifyListeners();
}
【问题讨论】:
-
您能说明类别的来源吗?
标签: flutter dart google-cloud-firestore