【发布时间】:2021-06-08 08:27:16
【问题描述】:
我想保存下载的视频,将其保存到一个临时文件中,该文件会在应用关闭时自动消失。在 Flutter 中有没有方便的方法呢? 我知道我们可以使用 path_provider 包在临时文件夹中生成一个文件,但该文件在用户关闭应用程序后不会消失。
【问题讨论】:
标签: flutter
我想保存下载的视频,将其保存到一个临时文件中,该文件会在应用关闭时自动消失。在 Flutter 中有没有方便的方法呢? 我知道我们可以使用 path_provider 包在临时文件夹中生成一个文件,但该文件在用户关闭应用程序后不会消失。
【问题讨论】:
标签: flutter
如果你想在 Flutter 中保存任何东西,我认为键值存储是最好的方法。在 Flutter 中有一个名为 shared_preferences 的包,它可以帮助您将键值数据存储在磁盘上。
我复制了shared_preferences包的官网。在这些网站上,您可以阅读到很多相关信息。
【讨论】:
试试flutter_cache_manager,你可以下载缓存中的文件并从缓存中删除:
getFileStream(url) returns a stream with the first result being the cached file and later optionally the downloaded file.
getFileStream(url, withProgress: true) when you set withProgress on true, this stream will also emit DownloadProgress when the file is not found in the cache.
downloadFile(url) directly downloads from the web.
getFileFromCache only retrieves from cache and returns no file when the file is not in the cache.
putFile gives the option to put a new file into the cache without downloading it.
removeFile removes a file from the cache.
emptyCache removes all files from the cache.
【讨论】: