clearCache static method
Implementation
static Future<String?> clearCache(context) async {
//此处展示加载loading
try {
var _tempDir = await getTemporaryDirectory();
double value = 0;
bool exists = await _tempDir.exists();
if (exists) {
value = await _getTotalSizeOfFilesInDir(_tempDir);
}
if (value <= 0) {
ToastUtil.show('暂无缓存');
} else if (value >= 0) {
toastLoading();
return Future.delayed(const Duration(seconds: 2), () async {
//删除缓存目录
await delDir(_tempDir);
ToastUtil.show('清理完成');
var size = await loadCache();
logger.d("size => $size");
return size;
});
}
} catch (e) {
ToastUtil.show('清除缓存失败');
} finally {
cancelLoading();
}
}