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 hasPermissionIoWeb();
if (!hasAccess) developer.log('❌ Permission access denied', name: 'Cached Media package');
cacheMaxSizeDefault = cacheMaxSize;
_showLogs = showLogs;
await initStreamListener(showLogs: showLogs, getStorage: getStorage);
tempDir = await getTemporaryDirectoryIoWeb();
if (clearCache) await clearCacheOnInit(getStorage);
isInitialized = true;
}
}