Saving Files
Save to device keeps a file on the person's phone or computer: a ticket, a receipt, a poster. An image goes to Photos; anything else goes where the person picks; on the web, the browser downloads it. One design works on iOS, Android and the web.
Adding it
Add Save to device to a button and fill in:
Open a file or save it?
Where it goes
An image (a JPEG, PNG, GIF, WebP or HEIC) goes to the photo library. iOS asks first, for photo saving: adding to Photos, never reading it. Its words come from App, Permission messages. Recent Android needs nothing; older Android asks to write (Flutter apps up to Android 9, Expo apps up to Android 12).
Any other file opens the system's own save dialog, and the person picks the folder. Closing it without saving runs nothing.
On the web both are downloaded, under the file's own name. The browser fetches the file from your app's address, so that address must be in Trusted Origins, as every other request from your web app needs. A link on another site that refuses it runs On error.
Save to device From: Storage, Bucket: tickets, File: the ticket's path
On success Show "Saved to your phone"
On denied Show "Turn on photo saving in Settings to keep it"Sharing a file
Share can carry a file too: set its File to From storage or From a link, the same way. The file is fetched first, then the share sheet opens with the file and the text beside it. Not fetched, On error runs, or the app says it couldn't share the file.
In the Expo app the file goes alone: its share sheet takes a file or words, not both, and it doesn't say whether anything was shared, so On shared and On cancelled don't run there. Checks says so. In a browser the file is shared where the browser can share files (most phones). Where it can't, On error runs, or the app says “This browser can't share files.” A browser opens its share sheet only within a few seconds of the tap, so share a large file with Save to device on the web.
Progress and Stop
Give Save to device, or a Share with a file, its own loading state. Its progress can then fill a text (“42%”) or a progress bar as the file comes, as an upload's does. A button running Cancel a download on that loading state stops it: nothing is saved or shared, nothing that followed runs, no message shows, and the progress goes back to 0%.
Share File: From storage, tickets, the ticket's path
Loading & errors: sending_ticket
Text Value: sending_ticket's progress
Stop Cancel a download: sending_ticket
Visible while sending_ticket is pendingWhat each export uses
Flutter. gal for Photos, file_picker's save dialog for other files, asking through permission_handler.
Expo. expo-media-library for Photos and expo-file-system for the download and the folder. The export blocks READ_MEDIA_VISUAL_USER_SELECTED, which expo-media-library declares: saving never reads the library.
Web. The browser's own download.
Sharing a file. Flutter: share_plus, the file fetched with http. Expo: expo-sharing, downloaded with expo-file-system. Web: the browser's own share sheet.
Trying it
In Preview nothing is fetched or written: it says the file would be saved, then runs On success. On a device, save an image and a PDF once each, and check Photos and the folder you picked. Share a PDF to Mail and check it arrives attached.