Initial draft

This commit is contained in:
Dennis Nemec
2025-09-20 16:14:06 +02:00
commit b19a6e1cd4
219 changed files with 10317 additions and 0 deletions

60
lib/util.dart Normal file
View File

@ -0,0 +1,60 @@
import 'package:intl/intl.dart';
import 'model/delivery.dart';
dynamic getValueOrThrowIfNotPresent(String key, Map<String, dynamic> json) {
if (!json.containsKey(key)) {
throw Exception("Wert '$key' in der Konfigurationsdatei nicht gefunden");
}
return json[key];
}
/// Returns the current date as string in format YYYY-MM-DD.
String getTodayDate() {
return DateFormat('yyyy-MM-dd').format(DateTime.now());
}
String concatenateRegexMatches(String input, String pattern) {
final regex = RegExp(pattern);
final matches = regex.allMatches(input);
return matches.fold("", (acc, match) => acc + match[0]!);
}
/// Return the value or the default value if the string is empty.
String getOrDefaultValueFromStr(String value, String defaultValue) {
if (value != "") {
return value;
} else {
return defaultValue;
}
}
DeliveryState getDeliveryStateFromString(String str) {
switch (str) {
case "laufend":
return DeliveryState.ongoing;
case "abgebrochen":
return DeliveryState.canceled;
case "vertagt":
return DeliveryState.onhold;
case "geliefert":
return DeliveryState.finished;
default:
throw Exception("Invalid state");
}
}
String getName(DeliveryState state) {
switch (state) {
case DeliveryState.ongoing:
return "laufend";
case DeliveryState.canceled:
return "abgebrochen";
case DeliveryState.onhold:
return "unterbrochen";
case DeliveryState.finished:
return "ausgeliefert";
}
}