【发布时间】:2021-10-31 16:04:59
【问题描述】:
下面是产品集合的 Firebase Firestore 数据库,代码能够从集合中获取所有其他数据,但只有颜色字段返回 null,我正在使用 strembuilder 以及产品和颜色模型。
如果您知道我如何实现这一点,我将竭诚为您提供帮助。
产品型号
class Product with ChangeNotifier {
String id;
String title;
String description;
String price;
String category;
String currency;
String condition;
String firestoreid;
String images;
Seller seller;
ProductColor colors;
Offer offer;
double rating;
bool isFavourite;
bool approved;
Product({
this.id,
this.title,
this.description,
this.category,
this.images,
this.colors,
this.rating,
this.price,
this.seller,
this.currency,
this.condition,
this.firestoreid,
this.approved,
this.isFavourite,
this.offer,
});
Product copy(
String id,
String title,
String description,
String price,
String category,
String currency,
String condition,
String firestoreid,
String images,
Seller seller,
ProductColor colors,
Offer offer,
double rating,
bool isFavourite,
bool approved,
) =>
Product(
id: id ?? this.id,
title: title ?? this.title,
description: description ?? this.description,
price: price ?? this.price,
category: category ?? this.category,
currency: currency ?? this.currency,
condition: condition ?? this.condition,
firestoreid: firestoreid ?? this.firestoreid,
images: images ?? this.images,
seller: seller ?? this.seller,
colors: colors ?? this.colors,
offer: offer ?? this.offer,
rating: rating ?? this.rating,
isFavourite: isFavourite ?? this.isFavourite,
approved: approved ?? this.approved,
);
static Product fromJson(Map<String, dynamic> json) => Product(
id: json['firestore_id'],
title: json['productName'],
description: json['productDescriptions'],
category: json['categoryName'],
images: json['image'],
colors: ProductColor.fromJson(json['color']),
rating: json[''],
price: json['price'],
seller: Seller.froJson(json['seller']),
approved: json['approved'],
currency: json['priceCurrency'],
condition: json['productCondition'],
firestoreid: json['firestore_id'],
);
}
颜色模型
class ProductColor {
String id;
Color color;
String qty;
String size;
ProductColor({
this.id,
this.color,
this.qty,
this.size,
});
static ProductColor fromJson(Map<String, dynamic> json) => ProductColor(
id: json[''],
color: json['color'],
qty: json['qty'],
size: json['size'],
);
Map<String, dynamic> toJson() => {
'id': id,
'color': color,
'qty': qty,
'size': size,
};
}
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore model