From b2effad6e52f14556e5f557c132f46452b448fa3 Mon Sep 17 00:00:00 2001 From: Mountains Date: Mon, 23 Sep 2024 14:53:55 +0800 Subject: [PATCH 1/2] Fix removeCacheFile --- flutter_cache_manager/lib/src/cache_store.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flutter_cache_manager/lib/src/cache_store.dart b/flutter_cache_manager/lib/src/cache_store.dart index bf283086..ca6e9188 100644 --- a/flutter_cache_manager/lib/src/cache_store.dart +++ b/flutter_cache_manager/lib/src/cache_store.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'dart:io'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; -import 'dart:io' as io; ///Flutter Cache Manager ///Copyright (c) 2019 Rene Floor @@ -184,7 +183,7 @@ class CacheStore { if (_futureCache.containsKey(cacheObject.key)) { await _futureCache.remove(cacheObject.key); } - final file = io.File(cacheObject.relativePath); + final file = await fileSystem.createFile(cacheObject.relativePath); if (file.existsSync()) { try { From 9d2dbe5e821e1f788b4d5f333322b4ce1c2e1d34 Mon Sep 17 00:00:00 2001 From: Mountains <583082772@qq.com> Date: Wed, 9 Oct 2024 22:08:24 +0800 Subject: [PATCH 2/2] Added test for removeCachedFile --- .../test/cache_store_test.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/flutter_cache_manager/test/cache_store_test.dart b/flutter_cache_manager/test/cache_store_test.dart index b9a7ccd4..ddc693a9 100644 --- a/flutter_cache_manager/test/cache_store_test.dart +++ b/flutter_cache_manager/test/cache_store_test.dart @@ -402,6 +402,24 @@ void main() { verify(config.mockRepo .deleteAll(argThat(containsAll([co1.id, co2.id, co3.id])))).called(1); }); + + test('Store should delete file when remove cached file', () async { + var config = createTestConfig(); + var store = CacheStore(config); + + await config.returnsFile(fileName); + config.returnsCacheObject(fileUrl, fileName, validTill, id: 1); + + var cacheObject = await store.retrieveCacheData(fileUrl); + + expect(cacheObject, isNotNull); + var fileInfo = await store.getFile(cacheObject!.key); + expect(await fileInfo?.file.exists(), isTrue); + + await store.removeCachedFile(cacheObject); + + expect(await fileInfo?.file.exists(), isFalse); + }); }); }