chore: add datestringcodec

This commit is contained in:
Yaros
2026-05-13 22:25:42 +02:00
parent 9e76f09c91
commit 156277c629
+17 -2
View File
@@ -50,8 +50,8 @@ enum MetadataKey<T extends Object> {
// Map
mapShowFavoriteOnly<bool>(.appConfig, 'map.showFavoriteOnly', false),
mapRelativeDate<int>(.appConfig, 'map.relativeDate', 0),
mapCustomFrom<String>(.appConfig, 'map.customFrom', ''),
mapCustomTo<String>(.appConfig, 'map.customTo', ''),
mapCustomFrom<String>(.appConfig, 'map.customFrom', '', _DateStringCodec()),
mapCustomTo<String>(.appConfig, 'map.customTo', '', _DateStringCodec()),
mapIncludeArchived<bool>(.appConfig, 'map.includeArchived', false),
mapThemeMode<ThemeMode>(.appConfig, 'map.themeMode', .system, _EnumCodec(ThemeMode.values)),
mapWithPartners<bool>(.appConfig, 'map.withPartners', false),
@@ -166,6 +166,21 @@ final class _ListCodec<T extends Object> extends _MetadataCodec<List<T>> {
}
}
final class _DateStringCodec extends _MetadataCodec<String> {
const _DateStringCodec();
@override
String encode(String value) => value;
@override
String? decode(String raw) {
if (raw.isEmpty) {
return raw;
}
return DateTime.tryParse(raw) != null ? raw : null;
}
}
final class _PrimitiveCodec<T extends Object> extends _MetadataCodec<T> {
final T? Function(String) _parse;