In a Flutter web app, when a button is tapped, I want to download a file and then show a confirmation snackbar:
onTap: () async {
saveSettings(artWork);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
backgroundColor: Colors.green,
content: Text('Artwork has been saved. File name: ${artWork.title + ".diy"}')));
Navigator.pop(context);}
where saveSettings() looks like this:
void saveSettings(ArtWork artWork) {
Uint8List pngBytes = encodeArt(artWork);
Blob blob = Blob([pngBytes], 'application/octet-stream');
String fileName = artWork.title + '.diy';
AnchorElement anchor = AnchorElement(
href: Url.createObjectUrlFromBlob(blob),
);
anchor.setAttribute("download", fileName);
anchor.click();
}
The web browser (Safari on iPad, Chrome on Windows) then asks the user if/where they want to download the file. My problem is that the confirmation snackbar is shown directly, even if the user rejects the download.
How can I wait for the download to complete?