我正在从事电子商务应用程序的项目。flutter对我来说是新的,所以请帮助我这是我从快速类型获得的模型。类型'Null'不是'Map'类型的子类型
OrderListModel orderListModelsFromJson(String str) => OrderListModel.fromJson(json.decode(str));
String orderListModelsToJson(OrderListModel data) => json.encode(data.toJson());
class OrderListModel {
OrderListModel({
this.error,
this.errorMessage,
this.content,
});
bool? error;
String? errorMessage;
Content? content;
factory OrderListModel.fromJson(Map<String, dynamic> json) => OrderListModel(
error: json["error"],
errorMessage: json["errorMessage"],
content: Content.fromJson(json["content"]),
);
Map<String, dynamic> toJson() => {
"error": error,
"errorMessage": errorMessage,
"content": content!.toJson(),
};
}
class Content {
Content({
this.currentPage,
this.data,
this.firstPageUrl,
this.from,
this.lastPage,
this.lastPageUrl,
this.nextPageUrl,
this.path,
this.perPage,
this.prevPageUrl,
this.to,
this.total,
});
int? currentPage;
List<Order>? data;
String? firstPageUrl;
int? from;
int? lastPage;
String? lastPageUrl;
String? nextPageUrl;
String? path;
String? perPage;
dynamic? prevPageUrl;
int? to;
int? total;
factory Content.fromJson(Map<String, dynamic> json) => Content(
currentPage: json["current_page"],
data: List<Order>.from(json["data"].map((x) => Order.fromJson(x))),
firstPageUrl: json["first_page_url"],
from: json["from"],
lastPage: json["last_page"],
lastPageUrl: json["last_page_url"],
nextPageUrl: json["next_page_url"],
path: json["path"],
perPage: json["per_page"],
prevPageUrl: json["prev_page_url"],
to: json["to"],
total: json["total"],
);
Map<String, dynamic> toJson() => {
"current_page": currentPage,
"data": List<dynamic>.from(data!.map((x) => x.toJson())),
"first_page_url": firstPageUrl,
"from": from,
"last_page": lastPage,
"last_page_url": lastPageUrl,
"next_page_url": nextPageUrl,
"path": path,
"per_page": perPage,
"prev_page_url": prevPageUrl,
"to": to,
"total": total,
};
}
class Order {
Order({
this.orderId,
this.shopId,
this.shop,
this.deliveryType,
this.netTotalAmount,
this.deliveryAddressId,
this.totalDiscount,
this.coupon,
this.scheduleTime,
this.orderReferenceId,
this.status,
this.orderPlaceTime,
this.deliveredTime,
this.deliveryStaffId,
this.updatedAt,
this.cartId,
this.adminServiceCharge,
this.shopEarning,
this.orderSuggestions,
this.deliverycharge,
this.partiallyComplete,
this.markReady,
this.partiallyCompleteReason,
this.productTotalAmount,
this.deliveryId,
this.tax,
this.taxAmount,
this.couponPercentage,
this.user,
this.address,
});
int? orderId;
int? shopId;
Shop? shop;
int? deliveryType;
double? netTotalAmount;
int? deliveryAddressId;
double? totalDiscount;
Coupon? coupon;
String? scheduleTime;
String? orderReferenceId;
Status? status;
DateTime? orderPlaceTime;
DateTime? deliveredTime;
int? deliveryStaffId;
List<dynamic>? updatedAt;
int? cartId;
String? adminServiceCharge;
String? shopEarning;
dynamic? orderSuggestions;
dynamic? deliverycharge;
int? partiallyComplete;
String? markReady;
dynamic? partiallyCompleteReason;
dynamic? productTotalAmount;
int? deliveryId;
int? tax;
int? taxAmount;
String? couponPercentage;
User? user;
dynamic? address;
factory Order.fromJson(Map<String, dynamic> json) => Order(
orderId: json["orderId"],
shopId: json["shopId"],
shop: Shop.fromJson(json["shop"]),
deliveryType: json["deliveryType"],
netTotalAmount: json["netTotalAmount"].toDouble(),
deliveryAddressId: json["deliveryAddressId"],
totalDiscount: json["totalDiscount"].toDouble(),
coupon: Coupon.fromJson(json["coupon"]),
scheduleTime: json["scheduleTime"],
orderReferenceId: json["orderReferenceId"],
status: Status.fromJson(json["status"]),
orderPlaceTime: DateTime.parse(json["orderPlaceTime"]),
deliveredTime: DateTime.parse(json["deliveredTime"]),
deliveryStaffId: json["deliveryStaffId"],
updatedAt: List<dynamic>.from(json["updated_at"].map((x) => x)),
cartId: json["cartId"],
adminServiceCharge: json["adminServiceCharge"],
shopEarning: json["shopEarning"],
orderSuggestions: json["orderSuggestions"],
deliverycharge: json["deliverycharge"],
partiallyComplete: json["partiallyComplete"],
markReady: json["markReady"],
partiallyCompleteReason: json["partiallyCompleteReason"],
productTotalAmount: json["productTotalAmount"],
deliveryId: json["deliveryId"],
tax: json["tax"],
taxAmount: json["taxAmount"],
couponPercentage: json["couponPercentage"],
user: User.fromJson(json["User"]),
address: json["Address"],
);
Map<String, dynamic> toJson() => {
"orderId": orderId,
"shopId": shopId,
"shop": shop!.toJson(),
"deliveryType": deliveryType,
"netTotalAmount": netTotalAmount,
"deliveryAddressId": deliveryAddressId,
"totalDiscount": totalDiscount,
"coupon": coupon!.toJson(),
"scheduleTime": scheduleTime,
"orderReferenceId": orderReferenceId,
"status": status!.toJson(),
"orderPlaceTime": orderPlaceTime!.toIso8601String(),
"deliveredTime": deliveredTime!.toIso8601String(),
"deliveryStaffId": deliveryStaffId,
"updated_at": List<dynamic>.from(updatedAt!.map((x) => x)),
"cartId": cartId,
"adminServiceCharge": adminServiceCharge,
"shopEarning": shopEarning,
"orderSuggestions": orderSuggestions,
"deliverycharge": deliverycharge,
"partiallyComplete": partiallyComplete,
"markReady": markReady,
"partiallyCompleteReason": partiallyCompleteReason,
"productTotalAmount": productTotalAmount,
"deliveryId": deliveryId,
"tax": tax,
"taxAmount": taxAmount,
"couponPercentage": couponPercentage,
"User": user!.toJson(),
"Address": address,
};
}
class Coupon {
Coupon({
this.id,
this.couponName,
this.couponCode,
this.discountPerscentage,
this.maxDiscount,
this.dateStart,
this.dateEnd,
this.status,
this.couponImage,
this.createdAt,
this.updatedAt,
this.outletId,
this.isblock,
this.isDeleted,
this.numberOfUses,
this.isAdminCoupon,
});
int? id;
String? couponName;
String? couponCode;
int? discountPerscentage;
int? maxDiscount;
dynamic? dateStart;
dynamic? dateEnd;
int? status;
dynamic? couponImage;
DateTime? createdAt;
DateTime? updatedAt;
int? outletId;
int? isblock;
int? isDeleted;
int? numberOfUses;
int? isAdminCoupon;
factory Coupon.fromJson(Map<String, dynamic> json) => Coupon(
id: json["id"],
couponName: json["couponName"],
couponCode: json["couponCode"],
discountPerscentage: json["discountPerscentage"],
maxDiscount: json["maxDiscount"],
dateStart: json["dateStart"],
dateEnd: json["dateEnd"],
status: json["status"],
couponImage: json["couponImage"],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
outletId: json["outletId"],
isblock: json["isblock"],
isDeleted: json["isDeleted"],
numberOfUses: json["numberOfUses"],
isAdminCoupon: json["isAdminCoupon"],
);
Map<String, dynamic> toJson() => {
"id": id,
"couponName": couponName,
"couponCode": couponCode,
"discountPerscentage": discountPerscentage,
"maxDiscount": maxDiscount,
"dateStart": dateStart,
"dateEnd": dateEnd,
"status": status,
"couponImage": couponImage,
"created_at": createdAt!.toIso8601String(),
"updated_at": updatedAt!.toIso8601String(),
"outletId": outletId,
"isblock": isblock,
"isDeleted": isDeleted,
"numberOfUses": numberOfUses,
"isAdminCoupon": isAdminCoupon,
};
}
class Shop {
Shop({
this.id,
this.name,
this.email,
this.image,
this.contactNumber,
this.address,
});
int? id;
String? name;
String? email;
String? image;
String? contactNumber;
Address? address;
这个下面的地址我得到了错误。
factory Shop.fromJson(Map<String, dynamic> json) => Shop(
id: json["id"],
name: json["name"],
email: json["email"],
image: json["image"],
contactNumber: json["contactNumber"],
address: Address.fromJson(json["Address"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"email": email,
"image": image,
"contactNumber": contactNumber,
"Address": address!.toJson(),
};
}
I/flutter(21615): type'Null'不是'Map'类型的子类型
class Address {
Address({
this.id,
this.userId,
this.location,
this.houseFlatNo,
this.fullAddress,
this.type,
this.unSaved,
this.latitude,
this.longitude,
this.isDeleted,
this.currentAddress,
this.streetNo,
this.streetName,
this.country,
this.zipcode,
this.city,
});
int? id;
int? userId;
String? location;
String? houseFlatNo;
String? fullAddress;
dynamic? type;
int? unSaved;
double? latitude;
double? longitude;
int? isDeleted;
int? currentAddress;
String? streetNo;
String? streetName;
String? country;
int? zipcode;
String? city;
factory Address.fromJson(Map<String, dynamic> json) => Address(
id: json["id"],
userId: json["userId"],
location: json["location"],
houseFlatNo: json["houseFlatNo"],
fullAddress: json["fullAddress"],
type: json["type"],
unSaved: json["unSaved"],
latitude: json["latitude"].toDouble(),
longitude: json["longitude"].toDouble(),
isDeleted: json["isDeleted"],
currentAddress: json["currentAddress"],
streetNo: json["streetNo"],
streetName: json["streetName"],
country: json["country"],
zipcode: json["zipcode"],
city: json["city"],
);
Map<String, dynamic> toJson() => {
"id": id,
"userId": userId,
"location": location,
"houseFlatNo": houseFlatNo,
"fullAddress": fullAddress,
"type": type,
"unSaved": unSaved,
"latitude": latitude,
"longitude": longitude,
"isDeleted": isDeleted,
"currentAddress": currentAddress,
"streetNo": streetNo,
"streetName": streetName,
"country": country,
"zipcode": zipcode,
"city": city,
};
}
class Status {
Status({
this.id,
this.name,
});
int? id;
dynamic? name;
factory Status.fromJson(Map<String, dynamic> json) => Status(
id: json["id"],
name: json["name"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
};
}
class User {
User({
this.id,
this.firstName,
this.lastName,
this.email,
this.mobileNumber,
this.countryCode,
});
int? id;
String? firstName;
dynamic? lastName;
String? email;
String? mobileNumber;
String? countryCode;
factory User.fromJson(Map<String, dynamic> json) => User(
id: json["id"],
firstName: json["firstName"],
lastName: json["lastName"],
email: json["email"],
mobileNumber: json["mobileNumber"],
countryCode: json["countryCode"],
);
Map<String, dynamic> toJson() => {
"id": id,
"firstName": firstName,
"lastName": lastName,
"email": email,
"mobileNumber": mobileNumber,
"countryCode": countryCode,
};
}
将您的工厂Shop. fromJson方法更改为:
factory Shop.fromJson(Map<String, dynamic> json) => Shop(
id: json["id"],
name: json["name"],
email: json["email"],
image: json["image"],
contactNumber: json["contactNumber"],
address: json['Address'] != null ? Address.fromJson(json["Address"]) : null,
);
Address. fromJson方法需要Map