clearTemporaryDirectoryCache function

Future<bool> clearTemporaryDirectoryCache()

Implementation

Future<bool> clearTemporaryDirectoryCache() async {
  Future<bool> delDir(FileSystemEntity file) async {
    try {
      if (file is Directory) {
        final List<FileSystemEntity> children = file.listSync();
        for (final FileSystemEntity child in children) {
          await delDir(child);
        }
      }
      await file.delete();
      return true;
    } catch (err) {
      logError(err);
      return false;
    }
  }

  try {
    Directory tempDir = await getTemporaryDirectory();
    // 删除缓存目录
    await delDir(tempDir).then((bool) {
      return true;
    });
    return false;
  } catch (err) {
    logError(err);
    return false;
  }
}