// 我在行中有错误:_picture = snapshot.data()[PICTURE]; ,它返回未处理的异常。 “List”类型不是“List”类型的子类型 This is the image of my firebase
=$F1
//也检测到的第二个错误来自行:products.add(ProductModel.fromSnapshot(product)); 两者都抛出未处理的异常类型'List'不是类型'的子类型列表'
import 'package:cloud_firestore/cloud_firestore.dart';
class ProductModel {
static const ID = "id";
static const NAME = "name";
static const PICTURE = "picture";
static const PRICE = "price";
static const DESCRIPTION = "description";
static const CATEGORY = "category";
static const QUANTITY = "quantity";
static const BRAND = "brand";
static const PAYSTACK_ID = "paystackId";
String _id;
String _name;
List<String> _picture;
String _description;
String _category;
String _brand;
int _quantity;
int _price;
String _paystackId;
String get id => _id;
String get name => _name;
List<String> get picture => _picture;
String get brand => _brand;
String get category => _category;
String get description => _description;
int get quantity => _quantity;
int get price => _price;
String get paystackId => _paystackId;
ProductModel.fromSnapshot(DocumentSnapshot snapshot) {
_id = snapshot.data()[ID];
_brand = snapshot.data()[BRAND];
_description = snapshot.data()[DESCRIPTION] ?? " ";
_price = snapshot.data()[PRICE].floor();
_category = snapshot.data()[CATEGORY];
_name = snapshot.data()[NAME];
_picture = snapshot.data()[PICTURE];
_paystackId = snapshot.data()[PAYSTACK_ID] ;
}
}
答案 0 :(得分:0)
当我将 List<dynamic>
更改为 {{1}} 时它起作用了。基本上,这可以自动扫描与“图片”集合相关联的不同图像。