83 lines
2.0 KiB
Dart
83 lines
2.0 KiB
Dart
|
|
|
|
class FilamentModel {
|
|
final String id;
|
|
final String name;
|
|
final String type; // PLA, ABS, PETG, etc.
|
|
final String color;
|
|
final double weight; // in Gramm
|
|
final double price; // Preis
|
|
final String? manufacturer;
|
|
final DateTime? purchaseDate;
|
|
final String? notes;
|
|
|
|
FilamentModel({
|
|
required this.id,
|
|
required this.name,
|
|
required this.type,
|
|
required this.color,
|
|
required this.weight,
|
|
required this.price,
|
|
this.manufacturer,
|
|
this.purchaseDate,
|
|
this.notes,
|
|
});
|
|
|
|
// JSON Serialisierung
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'name': name,
|
|
'type': type,
|
|
'color': color,
|
|
'weight': weight,
|
|
'price': price,
|
|
'manufacturer': manufacturer,
|
|
'purchaseDate': purchaseDate?.toIso8601String(),
|
|
'notes': notes,
|
|
};
|
|
}
|
|
|
|
// JSON Deserialisierung
|
|
factory FilamentModel.fromJson(Map<String, dynamic> json) {
|
|
return FilamentModel(
|
|
id: json['id'] as String,
|
|
name: json['name'] as String,
|
|
type: json['type'] as String,
|
|
color: json['color'] as String,
|
|
weight: (json['weight'] as num).toDouble(),
|
|
price: (json['price'] as num).toDouble(),
|
|
manufacturer: json['manufacturer'] as String?,
|
|
purchaseDate: json['purchaseDate'] != null
|
|
? DateTime.parse(json['purchaseDate'] as String)
|
|
: null,
|
|
notes: json['notes'] as String?,
|
|
);
|
|
}
|
|
|
|
// CopyWith für Updates
|
|
FilamentModel copyWith({
|
|
String? id,
|
|
String? name,
|
|
String? type,
|
|
String? color,
|
|
double? weight,
|
|
double? price,
|
|
String? manufacturer,
|
|
DateTime? purchaseDate,
|
|
String? notes,
|
|
}) {
|
|
return FilamentModel(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
type: type ?? this.type,
|
|
color: color ?? this.color,
|
|
weight: weight ?? this.weight,
|
|
price: price ?? this.price,
|
|
manufacturer: manufacturer ?? this.manufacturer,
|
|
purchaseDate: purchaseDate ?? this.purchaseDate,
|
|
notes: notes ?? this.notes,
|
|
);
|
|
}
|
|
}
|