refactor(apps): 主题系统迁移至 ColorScheme + 扩展架构并支持 Dark Mode

This commit is contained in:
qzl
2026-03-27 19:07:39 +08:00
parent ecc1ec6ce4
commit ae29a8209b
146 changed files with 4301 additions and 3200 deletions
@@ -1,57 +1,49 @@
import 'dart:async';
import '../../../core/cache/cache_entry.dart';
import '../../../core/cache/cache_invalidator.dart';
import '../../../core/cache/hybrid_cache_store.dart';
import '../../../data/cache/cache_entry.dart';
import '../../../data/cache/cache_invalidator.dart';
import '../../../data/cache/cache_policy.dart';
import '../../../data/cache/cached_repository.dart';
import 'todo_api.dart';
class TodoRepository {
class TodoRepository extends CachedRepository<List<TodoResponse>> {
static const String pendingListKey = 'todo:list:pending';
final TodoApi api;
final HybridCacheStore store;
final CacheInvalidator invalidator;
final DateTime Function() now;
TodoRepository({
required this.api,
required this.store,
required super.store,
required this.invalidator,
DateTime Function()? now,
}) : now = now ?? DateTime.now;
super.now,
}) : super(
policy: const CachePolicy(
softTtl: Duration(days: 3650),
hardTtl: Duration(days: 3650),
minRefreshInterval: Duration(days: 3650),
),
);
Future<List<TodoResponse>> getPendingTodos({
bool forceRefresh = false,
}) async {
if (!forceRefresh) {
final cached = await store.read<CacheEntry<List<TodoResponse>>>(
pendingListKey,
);
if (cached != null) {
return cached.value;
}
}
final remote = await api.getPendingTodos();
await store.write<CacheEntry<List<TodoResponse>>>(
pendingListKey,
CacheEntry(value: remote, fetchedAt: now()),
return getOrLoad(
key: pendingListKey,
forceRefresh: forceRefresh,
loadFromRemote: api.getPendingTodos,
);
return remote;
}
Future<void> completeTodo(String id) async {
final cached = await store.read<CacheEntry<List<TodoResponse>>>(
final CacheEntry<List<TodoResponse>>? cached = await readCacheEntry(
pendingListKey,
);
if (cached != null) {
final next = cached.value
.where((todo) => todo.id != id)
.toList(growable: false);
await store.write<CacheEntry<List<TodoResponse>>>(
pendingListKey,
CacheEntry(value: next, fetchedAt: now()),
);
await writeCacheEntry(pendingListKey, next);
}
try {