Skip to content

Commit

Permalink
Merge pull request #1507 from stakanojmdc/master
Browse files Browse the repository at this point in the history
Fix Issue 1505(Fix cache delete)
  • Loading branch information
navaronbracke authored Aug 16, 2024
2 parents cc26969 + 2c6747f commit 8bbe066
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.1.2
### Android
- Fixes a cache deletion issue [#1505](https://github.com/miguelpruivo/flutter_file_picker/issues/1505)

## 8.1.1
### Web
- Migrate the web example to use the new web bootstrapping, introduced in Flutter 3.22.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,7 @@ public static HashMap<String, Object> createFileInfoMap(File compressedImageFile
public static boolean clearCache(final Context context) {
try {
final File cacheDir = new File(context.getCacheDir() + "/file_picker/");
final File[] files = cacheDir.listFiles();

if (files != null) {
for (final File file : files) {
file.delete();
}
}
recursiveDeleteFile(cacheDir);
} catch (final Exception ex) {
Log.e(TAG, "There was an error while clearing cached files: " + ex.toString());
return false;
Expand Down Expand Up @@ -471,4 +465,18 @@ private static String getDocumentPathFromTreeUri(final Uri treeUri) {
else return File.separator;
}

private static void recursiveDeleteFile(final File file) throws Exception {
if (file == null || !file.exists()) {
return;
}

if (file.isDirectory()) {
for (File child : file.listFiles()) {
recursiveDeleteFile(child);
}
}

file.delete();
}

}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
repository: https://github.com/miguelpruivo/flutter_file_picker
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
version: 8.1.1
version: 8.1.2

dependencies:
flutter:
Expand Down

0 comments on commit 8bbe066

Please sign in to comment.