initStreamListener function
Future<void>
initStreamListener(
{ - bool showLogs = false,
- required GetStorage getStorage,
})
Implementation
Future<void> initStreamListener({bool showLogs = false, required GetStorage getStorage}) async {
getStorage.listenKey(keyName, (all) async {
final allData = AllCachedMediaInfo.fromJson(json.decode(all));
final p0 = <CachedMediaInfo>[];
p0.addAll(allData.cachedMediaInfo ?? []);
allCachedMediaInfo.clear();
allCachedMediaInfo.addAll(p0);
currentCacheSize = calculateCacheSize(p0);
if (getShowLogs) {
developer.log('''
- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -
Media in cache: ${p0.length}
Current Cache Size: ${currentCacheSize.toStringAsFixed(3)}
Cache Max Size: $cacheMaxSizeDefault
- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -
''', name: 'Cached Media package');
}
if (currentCacheSize > cacheMaxSizeDefault) {
await reduceCacheSize(getStorage, p0);
}
});
}