add two views
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
class BauteilFilamentModel {
|
||||
final String filamentId;
|
||||
final String? anwendungId;
|
||||
final double verbrauchGramm;
|
||||
|
||||
const BauteilFilamentModel({
|
||||
required this.filamentId,
|
||||
this.anwendungId,
|
||||
this.verbrauchGramm = 0,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'filamentId': filamentId,
|
||||
'anwendungId': anwendungId,
|
||||
'verbrauchGramm': verbrauchGramm,
|
||||
};
|
||||
|
||||
factory BauteilFilamentModel.fromJson(Map<String, dynamic> json) =>
|
||||
BauteilFilamentModel(
|
||||
filamentId: json['filamentId'] as String,
|
||||
anwendungId: json['anwendungId'] as String?,
|
||||
verbrauchGramm: (json['verbrauchGramm'] as num?)?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
class BauteilModel {
|
||||
final String bauteilId;
|
||||
final DateTime erstelltAm;
|
||||
final String name;
|
||||
final String verwendung;
|
||||
final int druckdauerMinuten;
|
||||
final double gewichtGramm;
|
||||
final double abfallGramm;
|
||||
final List<BauteilFilamentModel> filamente;
|
||||
final String? fotoBase64;
|
||||
|
||||
const BauteilModel({
|
||||
required this.bauteilId,
|
||||
required this.erstelltAm,
|
||||
required this.name,
|
||||
required this.verwendung,
|
||||
required this.druckdauerMinuten,
|
||||
required this.gewichtGramm,
|
||||
required this.abfallGramm,
|
||||
required this.filamente,
|
||||
this.fotoBase64,
|
||||
});
|
||||
|
||||
double get gesamtverbrauchGramm => gewichtGramm + abfallGramm;
|
||||
|
||||
Uint8List? get fotoBytes {
|
||||
if (fotoBase64 == null) return null;
|
||||
try {
|
||||
return base64Decode(fotoBase64!);
|
||||
} on FormatException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
BauteilModel copyWith({
|
||||
required String bauteilId,
|
||||
required DateTime erstelltAm,
|
||||
}) => BauteilModel(
|
||||
bauteilId: bauteilId,
|
||||
erstelltAm: erstelltAm,
|
||||
name: name,
|
||||
verwendung: verwendung,
|
||||
druckdauerMinuten: druckdauerMinuten,
|
||||
gewichtGramm: gewichtGramm,
|
||||
abfallGramm: abfallGramm,
|
||||
filamente: filamente,
|
||||
fotoBase64: fotoBase64,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'bauteilId': bauteilId,
|
||||
'erstelltAm': erstelltAm.toIso8601String(),
|
||||
'name': name,
|
||||
'verwendung': verwendung,
|
||||
'druckdauerMinuten': druckdauerMinuten,
|
||||
'gewichtGramm': gewichtGramm,
|
||||
'abfallGramm': abfallGramm,
|
||||
'filamente': filamente.map((item) => item.toJson()).toList(),
|
||||
'fotoBase64': fotoBase64,
|
||||
};
|
||||
|
||||
factory BauteilModel.fromJson(Map<String, dynamic> json) => BauteilModel(
|
||||
bauteilId: json['bauteilId'] as String,
|
||||
erstelltAm: DateTime.parse(json['erstelltAm'] as String),
|
||||
name: json['name'] as String,
|
||||
verwendung: json['verwendung'] as String,
|
||||
druckdauerMinuten: json['druckdauerMinuten'] as int,
|
||||
gewichtGramm: (json['gewichtGramm'] as num).toDouble(),
|
||||
abfallGramm: (json['abfallGramm'] as num).toDouble(),
|
||||
fotoBase64: json['fotoBase64'] as String?,
|
||||
filamente: (json['filamente'] as List)
|
||||
.map(
|
||||
(item) => BauteilFilamentModel.fromJson(
|
||||
Map<String, dynamic>.from(item as Map),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user