【发布时间】:2021-08-25 22:43:47
【问题描述】:
我有以下 StoreModel 类;
class StoreModel {
StoreModel(
{@required this.stripeCustomerId,
@required this.dateCreated,
@required this.storeSchedule,
@required this.expired,
@required this.userUid,
@required this.images,
@required this.thumbs,
@required this.location,
@required this.address,
@required this.phone,
@required this.garden,
@required this.farm,
@required this.craft,
@required this.cook,
@required this.description,
});
String stripeCustomerId;
Timestamp dateCreated;
Map<String, List<bool>> storeSchedule; //< here
bool expired = false;
String userUid;
List<String> images;
List<String> thumbs;
GeoPoint location;
String address;
String phone;
bool garden;
bool farm;
bool craft;
bool cook;
String description;
factory StoreModel.fromMap(Map<String, dynamic> data()) {
if (data() == null) {
return null;
}
final String stripeCustomerId = data()['customer_id'];
final Timestamp dateCreated = data()['dateCreated'];
final Map<String, List<bool>> storeSchedule = Map.from(data()['storeSchedule']); // <-- and here
final bool expired = data()['expired'];
final String userUid = data()['userUid'];
final List<String> images = List.from(data()['images']);
final List<String> thumbs = List.from(data()['thumbs']);
final GeoPoint location = data()['location'];
final String address = data()['address'];
final String phone = data()['phone'];
final bool garden = data()['garden'];
final bool farm = data()['farm'];
final bool craft = data()['craft'];
final bool cook = data()['cook'];
final String description = data()['description'];
return StoreModel(
stripeCustomerId: stripeCustomerId,
dateCreated: dateCreated,
storeSchedule: storeSchedule,
expired: expired,
userUid: userUid,
images: images,
thumbs: thumbs,
location: location,
address: address,
phone: phone,
garden: garden,
farm: farm,
craft: craft,
cook: cook,
description: description,
);
}
Map<String, dynamic> toMap() {
return {
'customer_id': stripeCustomerId,
'dateCreated': dateCreated,
'storeSchedule': storeSchedule,
'expired': expired,
'userUid': userUid,
'images': images,
'thumbs': thumbs,
'location': location,
'address': address,
'phone': phone,
'garden': garden,
'farm': farm,
'craft': craft,
'cook': cook,
'description' : description,
};
}
}
我有一个由 Map
Map<String, List<bool>> calendarCompile = {
'0': [false, false, false, false, false, false, false, false],
'1': [false, false, false, false, false, false, false, false],
'2': [false, false, false, false, false, false, false, false],
'3': [false, false, false, false, false, false, false, false],
'4': [false, false, false, false, false, false, false, false],
'5': [false, false, false, false, false, false, false, false],
'6': [false, false, false, false, false, false, false, false],
};
上传到 Firestore 可以完美运行,但从 Firestore 获取并使用 From.Map 工厂函数返回 > 未处理的异常:类型“列表”不是类型转换中“列表”类型的子类型。有什么想法吗?
【问题讨论】:
-
您的 storeSchedule 变量是 Map
> 但您的 from.Map 方法返回 Map 转换可能像 ( Map >)Map .from(data()['storeSchedule'])
标签: flutter dart google-cloud-firestore