Files
flutter_tank_web_app/lib/models/tank_guru_directus_model.dart
T
2026-09-26 20:03:58 +02:00

58 lines
1.5 KiB
Dart

class TankGuruDirectusModel {
int? iD;
String? userIdentId;
String? tankDate;
String? odometer;
String? liter;
String? pricePerLiter;
String? standort;
String? createdAt;
String? szPriceTotal;
TankGuruDirectusModel(
{this.iD,
this.userIdentId,
this.tankDate,
this.odometer,
this.liter,
this.pricePerLiter,
this.standort,
this.createdAt,
this.szPriceTotal});
TankGuruDirectusModel.fromJson(Map<String, dynamic> json) {
iD = json['ID'];
userIdentId = json['UserIdentId'];
tankDate = json['TankDate'];
odometer = json['Odometer'];
liter = json['Liter'];
pricePerLiter = json['PricePerLiter'];
standort = json['Standort'];
createdAt = json['CreatedAt'];
// Berechnung des Gesamtpreises
if (liter != null && pricePerLiter != null) {
double literValue = double.tryParse(liter!) ?? 0.0;
double pricePerLiterValue = double.tryParse(pricePerLiter!) ?? 0.0;
szPriceTotal = (literValue * pricePerLiterValue).toStringAsFixed(2);
} else {
szPriceTotal = '0.00';
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['ID'] = iD;
data['UserIdentId'] = userIdentId;
data['TankDate'] = tankDate;
data['Odometer'] = odometer;
data['Liter'] = liter;
data['PricePerLiter'] = pricePerLiter;
data['Standort'] = standort;
data['CreatedAt'] = createdAt;
data['SzPriceTotal'] = szPriceTotal;
return data;
}
}