class HistoryTransactionModel { HistoryTransactionModel({ this.orderId, this.totalPrice, this.date, this.dateExpired, this.paymentDetail, this.statusPayment, this.courses, this.discountPrice, this.token, }); final String? orderId; final DateTime? date; final DateTime? dateExpired; final List? courses; final int? totalPrice; final int? discountPrice; final PaymentDetail? paymentDetail; final String? statusPayment; final String? token; factory HistoryTransactionModel.fromJson(Map json) { int timestamp = int.parse(json["date"]); int timestampExpired = int.parse(json["date_expired"]); return HistoryTransactionModel( orderId: json['order_id'] ?? '', totalPrice: json["sub_total"] ?? 0, discountPrice: json["discount_price"] ?? 0, date: DateTime.fromMillisecondsSinceEpoch(timestamp * 1000), dateExpired: DateTime.fromMillisecondsSinceEpoch(timestamp * 1000), paymentDetail: PaymentDetail.fromJson(json["payment_detail"] ?? {}), statusPayment: json["status"] ?? '', token: json['token'] ?? '', courses: json["course"] != null ? List.from( json["course"].map((x) => DataCourses.fromJson(x))).toList() : []); } Map toJson() => { 'order_id': orderId, "sub_total": totalPrice, "discountPrice": discountPrice, "payment_type": paymentDetail, "status": statusPayment, "token": token, 'course': courses != null ? List.from(courses!.map((x) => x.toJson())).toList() : [] }; } class DataCourses { final String? courseId, thumbnail, title, instructor, price; DataCourses( {this.courseId, this.title, this.price, this.instructor, this.thumbnail}); factory DataCourses.fromJson(Map json) => DataCourses( courseId: json['id'] ?? '', title: json['title'] ?? '', price: json['price'] ?? '', thumbnail: json['thumbnail'] ?? '', instructor: json['instructor'] ?? '', ); Map toJson() => { 'id': courseId, 'title': title, 'price': price, 'thumbnail': thumbnail, 'instructor': instructor }; } class PaymentDetail { String? paymentType; String? bank; String? vaNumber; String? store; PaymentDetail({this.paymentType, this.bank, this.vaNumber, this.store}); PaymentDetail.fromJson(Map json) { paymentType = json['payment_type'] ?? ''; bank = json['bank'] ?? ''; vaNumber = json['va_number'] ?? ''; store = json['store'] ?? ''; } Map toJson() { final Map data = new Map(); data['payment_type'] = this.paymentType; data['bank'] = this.bank; data['va_number'] = this.vaNumber; return data; } }