getLocalTemporaryFile method
获取临时目录文件,只能由该应用访问,系统可随时清除的临时目录(缓存) 指向设备上临时目录的路径,该目录没有备份,适合存储下载文件的缓存。 此目录中的文件可以随时清除。这不会返回一个新的临时目录。 相反,调用者负责在这个目录中创建(和清理)文件或目录。这个目录的作用域是调用应用程序。 在iOS上,它使用“NSCachesDirectory”API。 在Android上,它在上下文中使用“getCacheDir”API。 临时目录: /data/user/0/com.xx.xxx/cache
Implementation
Future<File?> getLocalTemporaryFile({required String fileName, String? filePath}) async {
try {
final dir = await getTemporaryDirectory();
return _getFile(dir, filePath, fileName);
} catch (e) {
logger.e(tag: TAG, e);
return null;
}
}