import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/shared/models/asset.dart'; import 'package:immich_mobile/shared/services/json_cache.dart'; class AssetCacheService extends JsonCache> { AssetCacheService() : super("asset_cache"); static Future>> _computeSerialize( List assets, ) async { return assets.map((e) => e.toJson()).toList(); } @override void put(List data) async { putRawData(await compute(_computeSerialize, data)); } static Future> _computeEncode(List data) async { return data.map((e) => Asset.fromJson(e)).whereNotNull().toList(); } @override Future?> get() async { try { final mapList = await readRawData() as List; final responseData = await compute(_computeEncode, mapList); return responseData; } catch (e) { debugPrint(e.toString()); await invalidate(); return null; } } } final assetCacheServiceProvider = Provider( (ref) => AssetCacheService(), );