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
+65
View File
@@ -0,0 +1,65 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:social_app/data/cache/cache_policy.dart';
import 'package:social_app/data/cache/cached_repository.dart';
import 'package:social_app/data/cache/hybrid_cache_store.dart';
import 'package:social_app/data/cache/memory_cache_store.dart';
import 'package:social_app/data/cache/persistent_cache_store.dart';
class _IntCachedRepository extends CachedRepository<int> {
int loadCount = 0;
_IntCachedRepository({required super.store})
: super(
policy: const CachePolicy(
softTtl: Duration(hours: 1),
hardTtl: Duration(hours: 2),
minRefreshInterval: Duration(minutes: 10),
),
);
Future<int> fetch({bool forceRefresh = false}) {
return getOrLoad(
key: 'test:number',
forceRefresh: forceRefresh,
loadFromRemote: () async {
loadCount += 1;
return loadCount;
},
);
}
}
void main() {
group('CachedRepository', () {
test('reads from cache after first load', () async {
final repo = _IntCachedRepository(
store: HybridCacheStore(
memory: MemoryCacheStore(),
persistent: PersistentCacheStore(),
),
);
final first = await repo.fetch();
final second = await repo.fetch();
expect(first, 1);
expect(second, 1);
expect(repo.loadCount, 1);
});
test('force refresh bypasses cached value', () async {
final repo = _IntCachedRepository(
store: HybridCacheStore(
memory: MemoryCacheStore(),
persistent: PersistentCacheStore(),
),
);
await repo.fetch();
final refreshed = await repo.fetch(forceRefresh: true);
expect(refreshed, 2);
expect(repo.loadCount, 2);
});
});
}