add two views
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user