Dart Null safety conversion is wrong
RmondJone opened this issue · comments
郭翰林 commented
The right one should be like this:
class RecommendResult {
RecommendResult({
this.pageSize,
this.pageNo,
this.totalCount,
this.resultData,
this.searchAfter,});
RecommendResult.fromJson(dynamic json) {
pageSize = json['pageSize'];
pageNo = json['pageNo'];
totalCount = json['totalCount'];
if (json['resultData'] != null) {
resultData = [];
json['resultData'].forEach((v) {
resultData?.add(RecommendProduct.fromJson(v));
});
}
searchAfter = json['searchAfter'];
}
int? pageSize;
int? pageNo;
int? totalCount;
List<RecommendProduct>? resultData;
String? searchAfter;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['pageSize'] = pageSize;
map['pageNo'] = pageNo;
map['totalCount'] = totalCount;
if (resultData != null) {
map['resultData'] = resultData?.map((v) => v.toJson()).toList();
}
map['searchAfter'] = searchAfter;
return map;
}
}
class RecommendProduct {
RecommendProduct({
this.brandName,
this.kzSkuCode,
this.isMarketItem,
this.searchAfter,
this.originalPrice,
this.isHaveStock,
this.oeCode,
this.supplierCode,
this.categoryName,
this.score,
this.itemId,
this.categoryId,
this.recommendReason,
this.itemName,
this.newPrice,
this.itemImage,
this.price,
this.tagInfos,
this.brandId,});
RecommendProduct.fromJson(dynamic json) {
brandName = json['brandName'];
kzSkuCode = json['kzSkuCode'];
isMarketItem = json['isMarketItem'];
searchAfter = json['searchAfter'];
originalPrice = json['originalPrice'];
isHaveStock = json['isHaveStock'];
oeCode = json['oeCode'];
supplierCode = json['supplierCode'];
categoryName = json['categoryName'];
score = json['score'];
itemId = json['itemId'];
categoryId = json['categoryId'];
recommendReason = json['recommendReason'];
itemName = json['itemName'];
newPrice = json['newPrice'];
itemImage = json['itemImage'];
price = json['price'];
if (json['tagInfos'] != null) {
tagInfos = [];
json['tagInfos'].forEach((v) {
tagInfos?.add(TagInfo.fromJson(v));
});
}
brandId = json['brandId'];
}
String? brandName;
String? kzSkuCode;
bool? isMarketItem;
String? searchAfter;
String? originalPrice;
bool? isHaveStock;
String? oeCode;
String? supplierCode;
String? categoryName;
double? score;
int? itemId;
int? categoryId;
String? recommendReason;
String? itemName;
String? newPrice;
String? itemImage;
String? price;
List<TagInfo>? tagInfos;
int? brandId;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['brandName'] = brandName;
map['kzSkuCode'] = kzSkuCode;
map['isMarketItem'] = isMarketItem;
map['searchAfter'] = searchAfter;
map['originalPrice'] = originalPrice;
map['isHaveStock'] = isHaveStock;
map['oeCode'] = oeCode;
map['supplierCode'] = supplierCode;
map['categoryName'] = categoryName;
map['score'] = score;
map['itemId'] = itemId;
map['categoryId'] = categoryId;
map['recommendReason'] = recommendReason;
map['itemName'] = itemName;
map['newPrice'] = newPrice;
map['itemImage'] = itemImage;
map['price'] = price;
if (tagInfos != null) {
map['tagInfos'] = tagInfos?.map((v) => v.toJson()).toList();
}
map['brandId'] = brandId;
return map;
}
}
class TagInfo {
TagInfo({
this.fontColor,
this.tagSubtitle,
this.shadingColor,
this.tagTitle,});
TagInfo.fromJson(dynamic json) {
fontColor = json['fontColor'];
tagSubtitle = json['tagSubtitle'];
shadingColor = json['shadingColor'];
tagTitle = json['tagTitle'];
}
String? fontColor;
String? tagSubtitle;
String? shadingColor;
String? tagTitle;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['fontColor'] = fontColor;
map['tagSubtitle'] = tagSubtitle;
map['shadingColor'] = shadingColor;
map['tagTitle'] = tagTitle;
return map;
}
}
Nato Boram commented
Duplicate of #1673