How to Resolve ‘PathNotFoundException’ When Deleting a File with flutter_cache_manager?

  • Error Log in the Console
PathNotFoundException: Cannot delete file, path="/Users/macbook/Library/Developer/CoreSimulator/Devices/6BC0E48C-DCBB-4CFE-81E6-DA6B4848CEDD/data/Containers/Data/Application/766DA7B0-D6CE-4677-973E-DBD5A105BB5A/Library/Caches/customCacheKey/21681c01-aace-11ee-8cc9-19b244f13814.jpg" (OS Error: No such file or directory, errno = 2) STACK_TRACE: #0      _checkForErrorResponse (dart:io/common.dart:42:9)<…>
flutter: \^[[38;5;196m│ ⛔ #1      _File._delete.<anonymous closure> (dart:io/file_impl.dart:298:7)<…>
flutter: \^[[38;5;196m│ ⛔ #2      _rootRunUnary (dart:async/zone.dart:1406:47)<…>
flutter: \^[[38;5;196m│ ⛔ #3      _CustomZone.runUnary (dart:async/zone.dart:1307:19)<…>
flutter: \^[[38;5;196m│ ⛔ <asynchronous suspension><…>
flutter: \^[[38;5;196m│ ⛔ #4      ForwardingFileSystemEntity.delete (package:file/src/forwarding/forwarding_file_system_entity.dart:66:12)<…>
forwarding_file_system_entity.dart:66
flutter: \^[[38;5;196m│ ⛔ <asynchronous suspension><…>
***flutter: \^[[38;5;196m│ ⛔ #5      CacheStore._removeCachedFile *** (package:flutter_cache_manager/src/cache_store.dart:187:7)<…>
cache_store.dart:187
flutter: \^[[38;5;196m│ ⛔ <asynchronous suspension><…>
flutter: \^[[38;5;196m│ ⛔ <…>
  • The problem points to this function from the package CacheStore._removeCachedFile

  • I can see from this function that, they have already check if the file exist before delete. Why this problem still occurs?

  • I am using: Flutter 3.7.5, flutter_cache_manager: ^3.3.1

I tried upgrade to the latest version of flutter_cache_manager(3.3.1), but the problem still occurs.

Leave a Comment