import 'package:intl/intl.dart'; class CustomerExerciseDevice { int? customerExerciseDeviceId; late int exerciseDeviceId; late int customerId; late bool favourite; late DateTime dateAdd; late String change; CustomerExerciseDevice({required this.exerciseDeviceId, required this.customerId, required this.favourite}) { dateAdd = DateTime.now(); } CustomerExerciseDevice.fromJson(Map json) { this.customerExerciseDeviceId = json['customerExerciseDeviceId']; this.exerciseDeviceId = json['exerciseDeviceId']; this.customerId = json['customerId']; this.favourite = json['favourite'] == 1 ? true : false; this.dateAdd = DateTime.parse(json['dateAdd']); } Map toJson() { if (customerExerciseDeviceId == null) { return { "exerciseDeviceId": exerciseDeviceId, "customerId": customerId, "favourite": favourite == true ? 1 : 0, "dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd), }; } else { return { "customerExerciseDeviceId": customerExerciseDeviceId, "exerciseDeviceId": exerciseDeviceId, "customerId": customerId, "favourite": favourite == true ? 1 : 0, "dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd), }; } } }