add two views

This commit is contained in:
atseirjo
2026-10-27 15:00:16 +01:00
parent 864da57537
commit 07a1bb02fd
42 changed files with 3582 additions and 346 deletions
+16 -3
View File
@@ -19,6 +19,19 @@ class KaufFilamentModel {
required this.gewicht,
});
/// Supports old purchases saved as "1kg" as well as gram values.
double? get gewichtGramm {
final match = RegExp(
r'^\s*(\d+(?:[.,]\d+)?)\s*(kg|g)?\s*$',
caseSensitive: false,
).firstMatch(gewicht);
if (match == null) return null;
final value = double.tryParse(match.group(1)!.replaceAll(',', '.'));
if (value == null || !value.isFinite) return null;
final grams = value * (match.group(2)?.toLowerCase() == 'kg' ? 1000 : 1);
return grams.isFinite ? grams : null;
}
Map<String, dynamic> toJson() => {
'filamentId': filamentId,
'kaufdatum': kaufdatum.toIso8601String(),
@@ -39,7 +52,7 @@ class KaufFilamentModel {
material: json['material'] as String,
preis: (json['preis'] as num).toDouble(),
farbe: json['farbe'] as String,
gewicht: json['gewicht'] ?? '1000'
gewicht: json['gewicht'] ?? '1000',
);
}
@@ -61,7 +74,7 @@ class KaufFilamentModel {
material: material ?? this.material,
preis: preis ?? this.preis,
farbe: farbe ?? this.farbe,
gewicht: gewicht ?? this.gewicht
gewicht: gewicht ?? this.gewicht,
);
}
}
}