You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/old_lib/models/device/device.dart

66 lines
1.8 KiB
Dart

3 years ago
class Device{
String id;
String serialNumber;
3 years ago
String number;
3 years ago
String brand;
String model;
DateTime productionDate;
DateTime supplyDate;
DateTime installDate;
DateTime receivingDate;
DateTime operationDate;
DateTime warrantyDate;
Device({
this.id,
this.serialNumber,
3 years ago
this.number,
3 years ago
this.brand,
this.model,
this.productionDate,
this.supplyDate,
this.installDate,
this.receivingDate,
this.operationDate,
this.warrantyDate,
});
factory Device.fromJson(Map<String,dynamic> parsedJson){
return Device(
id: parsedJson["nid"] ?? parsedJson["id"],
serialNumber: parsedJson["sn"] ?? parsedJson["value"],
3 years ago
number: parsedJson["asset_no"],
3 years ago
brand: parsedJson["brand"].toString(),
model: parsedJson["model"].toString(),
productionDate: getDateFromString(parsedJson["production_date"]),
supplyDate: getDateFromString(parsedJson["supply_date "]),
installDate: getDateFromString(parsedJson["install_date "]),
receivingDate: getDateFromString(parsedJson["receving_date "]),
operationDate: getDateFromString(parsedJson["operation_date "]),
warrantyDate: getDateFromString(parsedJson["warranty_date "]),
);
}
factory Device.fromDevice(Device device){
return Device(
id: device.id,
serialNumber: device.serialNumber,
3 years ago
number: device.number,
3 years ago
brand: device.brand,
model: device.model,
productionDate: device.productionDate,
supplyDate: device.supplyDate,
installDate: device.installDate,
receivingDate: device.receivingDate,
operationDate: device.operationDate,
warrantyDate: device.warrantyDate,
);
}
}
DateTime getDateFromString(String unixDate){
if(unixDate == null)
return null;
return DateTime.fromMillisecondsSinceEpoch(
int.parse(unixDate));
}