In my Flutter application I need to allow admin users to download a CSV file with all the data entered into Firebase.
To do this, admins must press a button. If they do it from the web, the file is downloaded via the browser, while if they are on another device, a dialog opens asking if they want to download or share the file.
Creating the file takes some time, so I would like to show a CircularProgressIndicator
while waiting for the AlertDialog
to open.
I don’t know how to do this though, because I typically show the CircularProgressIndicator
when calling a Future
function via FutureBuilder
, but showDialog
doesn’t return a Widget
.
So how can I show a CircularProgressIndicator
before opening AlertDialog
?
Here is my code, thanks in advance!
FilledButton.icon(
onPressed: () async {
// This function creates a CSV file by retrieving data from Firebase,
// and takes some time to run
final String fileData = await getCsv();
if (kIsWeb) {
// running on the web
downloadFileOnWeb(fileData);
} else {
// NOT running on the web
if (!context.mounted) return;
return showDialog<void>(
context: context,
builder: (context) => AlertDialog(
content: const Text("Get report"),
actions: [
IconButton(
icon: const Icon(Icons.download),
onPressed: () => downloadFile(fileData),
),
IconButton(
icon: const Icon(Icons.share),
onPressed: () => shareFile(fileData),
),
],
),
);
}
},
icon: const Icon(Icons.file_open),
label: const Text("Report"),
),