import 'dart:convert';
SendDataModel sendDataModelFromJson(String str) => SendDataModel.fromJson(json.decode(str));
String sendDataModelToJson(SendDataModel data) => json.encode(data.toJson());
class SendDataModel {
SendDataModel({
this.branchUuid,
this.date,
this.time,
this.services,
this.packages,
this.remarks,
this.tax,
this.discount,
this.coupon,
});
String? branchUuid;
String? date;
String? time;
List<SendDataModelService>? services;
List<Package>? packages;
String? remarks;
int? tax;
int? discount;
String? coupon;
factory SendDataModel.fromJson(Map<String, dynamic> json) => SendDataModel(
branchUuid: json["branch_uuid"] == null ? null : json["branch_uuid"],
date: json["date"] == null ? null : json["date"],
time: json["time"] == null ? null : json["time"],
services: json["services"] == null ? null : List<SendDataModelService>.from(json["services"].map((x) => SendDataModelService.fromJson(x))),
packages: json["packages"] == null ? null : List<Package>.from(json["packages"].map((x) => Package.fromJson(x))),
remarks: json["remarks"] == null ? null : json["remarks"],
tax: json["tax"] == null ? null : json["tax"],
discount: json["discount"] == null ? null : json["discount"],
coupon: json["coupon"] == null ? null : json["coupon"],
);
Map<String, dynamic> toJson() => {
"branch_uuid": branchUuid == null ? null : branchUuid,
"date": date == null ? null : date,
"time": time == null ? null : time,
"services": services == null ? null : List<dynamic>.from(services!.map((x) => x.toJson())),
"packages": packages == null ? null : List<dynamic>.from(packages!.map((x) => x.toJson())),
"remarks": remarks == null ? null : remarks,
"tax": tax == null ? null : tax,
"discount": discount == null ? null : discount,
"coupon": coupon == null ? null : coupon,
};
}
class Package {
Package({
this.uuid,
this.services,
});
String? uuid;
List<PackageService>? services;
factory Package.fromJson(Map<String, dynamic> json) => Package(
uuid: json["uuid"] == null ? null : json["uuid"],
services: json["services"] == null ? null : List<PackageService>.from(json["services"].map((x) => PackageService.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"uuid": uuid == null ? null : uuid,
"services": services == null ? null : List<dynamic>.from(services!.map((x) => x.toJson())),
};
}
class PackageService {
PackageService({
this.uuid,
});
String? uuid;
factory PackageService.fromJson(Map<String, dynamic> json) => PackageService(
uuid: json["uuid"] == null ? null : json["uuid"],
);
Map<String, dynamic> toJson() => {
"uuid": uuid == null ? null : uuid,
};
}
class SendDataModelService {
SendDataModelService({
this.uuid,
this.staffUuid,
});
String? uuid;
String? staffUuid;
factory SendDataModelService.fromJson(Map<String, dynamic> json) => SendDataModelService(
uuid: json["uuid"] == null ? null : json["uuid"],
staffUuid: json["staff_uuid"] == null ? null : json["staff_uuid"],
);
Map<String, dynamic> toJson() => {
"uuid": uuid == null ? null : uuid,
"staff_uuid": staffUuid == null ? null : staffUuid,
};
}
首先创建发送数据模型。
late SendDataModel data;
data = SendDataModel(
branchUuid: "branchUuid",
coupon: "coupon",
date: "date",
time: "time",
discount: 12345,
remarks: "remarks",
tax: 12345,
);
List<SendDataModelService>? sendDataModelServiceList = [];
// If you have an expandable list
// If you keep the data as List<SendDataModelService> while keeping the data initially, you can make data.service = yourList without the need for ".add".
sendDataModelServiceList.add(SendDataModelService(uuid: "uuid", staffUuid: "staffUuid"));
data.services = sendDataModelServiceList;
List<Package> sendDataModelPackageList = [];
List<PackageService> tmpPackageServiceList = [];
tmpPackageServiceList.add(PackageService(uuid: "uuid"));
sendDataModelPackageList.add(Package(uuid: "uuid", services: tmpPackageServiceList));
// The important thing here is to keep your data in the model type that was created when you first created it, so your data will not be mixed.
var encodedData = jsonEncode(data);
如果你想通过 formData 发送。
formData: FormData.fromMap({
"formDataKey": jsonEncode({
data,
}),
}),