add some new features

This commit is contained in:
2026-10-29 15:03:48 +01:00
parent c876405a8f
commit 20012db615
39 changed files with 2908 additions and 97 deletions
+27 -4
View File
@@ -2,6 +2,7 @@ import 'dart:convert';
import '../helper/storage_keys.dart';
import 'anwendung_model.dart';
import 'abfall_model.dart';
import 'bauteil_model.dart';
import 'kauf_filament_model.dart';
@@ -11,6 +12,7 @@ class BackupModel {
StorageKeys.anwendungen,
StorageKeys.bauteile,
StorageKeys.materialien,
StorageKeys.abfaelle,
];
final Map<String, List<Map<String, dynamic>>> data;
@@ -34,9 +36,12 @@ class BackupModel {
final raw = json['daten'] as Map;
final data = <String, List<Map<String, dynamic>>>{
for (final key in keys)
key: (raw[key] as List)
.map((item) => Map<String, dynamic>.from(item as Map))
.toList(),
key:
((key == StorageKeys.abfaelle && !raw.containsKey(key))
? <dynamic>[]
: raw[key] as List)
.map((item) => Map<String, dynamic>.from(item as Map))
.toList(),
};
final filamentIds = <String>{};
for (final json in data[StorageKeys.filamente]!) {
@@ -45,7 +50,10 @@ class BackupModel {
!filamentIds.add(item.filamentId) ||
item.material.trim().isEmpty ||
!_positive(item.gewichtGramm) ||
!_nonNegative(item.preis)) {
!_nonNegative(item.preis) ||
(item.bruttoGewichtGramm != null &&
(!_positive(item.bruttoGewichtGramm) ||
item.bruttoGewichtGramm! < item.gewichtGramm!))) {
throw const FormatException();
}
}
@@ -71,6 +79,11 @@ class BackupModel {
item.druckdauerMinuten <= 0 ||
!_positive(item.gewichtGramm) ||
!_nonNegative(item.abfallGramm) ||
(item.abfallKosten != null && !_nonNegative(item.abfallKosten!)) ||
(item.materialKosten != null &&
!_nonNegative(item.materialKosten!)) ||
(item.aufschlagProzent != null &&
!_nonNegative(item.aufschlagProzent!)) ||
(item.gesamtpreis != null && !_nonNegative(item.gesamtpreis!)) ||
item.filamente.isEmpty ||
item.filamente.any(
@@ -82,6 +95,16 @@ class BackupModel {
}
if (item.fotoBase64 != null) base64Decode(item.fotoBase64!);
}
final wasteIds = <String>{};
for (final json in data[StorageKeys.abfaelle]!) {
final item = AbfallModel.fromJson(json);
if (item.abfallId.isEmpty ||
!wasteIds.add(item.abfallId) ||
!_positive(item.gewichtGramm) ||
!_nonNegative(item.kosten)) {
throw const FormatException();
}
}
final materials = data[StorageKeys.materialien]!;
if (materials.isNotEmpty) {
if (materials.length != 1) throw const FormatException();