initializeCachedMedia function
The function initializeCachedMedia() must be placed after WidgetsFlutterBinding.ensureInitialized()
You can define the size in megabytes(e.g. 100 MB) for cacheMaxSize. It will help maintain the performance of your app.
Set showLogs to true to show logs about the cache behavior & sizes.
Implementation
Future<void> initializeCachedMedia({
double cacheMaxSize = 100,
bool showLogs = false,
bool clearCache = false,
required GetStorage getStorage,
}) async {
if (!isInitialized) {
final hasAccess = await hasPermission();
if (hasAccess) {
developer.log('❌ Permission access denied', name: 'Cached Media package');
}
cacheMaxSizeDefault = cacheMaxSize * 1000000;
_showLogs = showLogs;
await initStreamListener(showLogs: showLogs, getStorage: getStorage);
tempDir = await getTemporaryDirectory();
if (clearCache) await clearCacheOnInit(getStorage);
isInitialized = true;
}
}