Reputation: 425
I want to save a download a video, save it into a temporary file that will automatically disappear when the app is closed. Is there a convenient way to do so in Flutter? I'm aware that we can use path_provider package to generate a file in temporary folder, but that file will not disappear after user close the app.
Upvotes: 1
Views: 4462
Reputation: 7601
try flutter_cache_manager, you can download the file in cache and remove it from cache:
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.
Upvotes: 0
Reputation: 265
If you want to save anything in Flutter, i think key-value storing is the best way to do. In Flutter there is a package called shared_preferences
which is help you to store key-value data on disc.
I copied the official websites of the shared_preferences package. On these websites you can read a lot about this.
https://flutter.dev/docs/cookbook/persistence/key-value
https://pub.dev/packages/shared_preferences
Upvotes: -3