import 'package:intl/intl.dart'; class Exercise { int? exerciseId; int? exerciseTypeId; int? customerId; double? quantity; String? unit; double? unitQuantity; DateTime? dateAdd; int? exercisePlanDetailId; int? trainingPlanDetailsId; String? datePart; double? calculated; String? summary; Exercise({this.exerciseTypeId, this.customerId, this.quantity, this.dateAdd}); Exercise.fromJson(Map json) { this.exerciseId = json['exerciseId']; this.exerciseTypeId = json['exerciseTypeId']; this.customerId = json['customerId']; this.quantity = json['quantity']; this.unit = json['unit']; this.unitQuantity = json['unitQuantity']; this.dateAdd = DateTime.parse(json['dateAdd']); this.datePart = DateFormat('yyyy-MM-dd').format(this.dateAdd!); this.calculated = quantity; this.exercisePlanDetailId = json['exercisePlanDetailId'] == "null" ? null : json['exercisePlanDetailId']; this.trainingPlanDetailsId = json['trainingPlanDetailsId'] == "null" ? null : json['trainingPlanDetailsId']; } Map toJson() => { "exerciseTypeId": exerciseTypeId, "customerId": customerId, "quantity": quantity, "unit": unit, "unitQuantity": unitQuantity, "dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!), "exercisePlanDetailId": exercisePlanDetailId, "trainingPlanDetailsId": trainingPlanDetailsId, }; Map toJsonDatePart() => { "exerciseTypeId": exerciseTypeId, "customerId": customerId, "quantity": quantity, 'calculated': calculated, "unit": unit, "unitQuantity": unitQuantity, "datePart": this.datePart, }; Exercise copy() { Exercise newExercise = Exercise(exerciseTypeId: this.exerciseTypeId, customerId: this.customerId, quantity: this.quantity, dateAdd: this.dateAdd); newExercise.unit = this.unit; newExercise.unitQuantity = this.unitQuantity; newExercise.exercisePlanDetailId = this.exercisePlanDetailId; return newExercise; } @override String toString() { return this.toJson().toString(); } }