0

I have written an upload function that uploads the selected files to Firebase Storage.

I can listen to the upload task and print the upload progress but I cannot somehow display it on a progress bar.

I even tried to display the progress as text on the alert dialogue but it always shows 0.00%

This is my upload Function:

uploadData() async {
  storageReference.putData(
   fileToUpload, SettabelMetaData(
                 contentType: 'image/*')
   ).snapshotEvents.listen((event) async {
       setState(() {
       _progress = event.bytesTransferred.toDouble() / 
                   event.totalBytes.toDouble();
       });
       debugPrint(_progress.toString());
       showDialog(
           context: context,
           builder: (ctx) {
           return AlertDialog(
             backgroundColor: Colors.black,
             actions: [
             LinearProgressIndicator(
             value: _progress,
             backgroundColor: Colors.white,
             color: Colors.red.shade700,
             )
            ],
           title: Text(
                  'Uploading...',
                  style: GoogleFonts.ubuntu(color: Colors.white),
                  ),
                  );
           });
        }
}

please let me know if I am doing anything wrong here, any suggestions will be of great help

OddlyGhost
  • 128
  • 2
  • 14
  • 1
    you need your dialog to be `'stateful'` check https://stackoverflow.com/questions/51962272/how-to-refresh-an-alertdialog-in-flutter – griffins May 02 '22 at 17:58
  • Understood let me try this out, thanks – OddlyGhost May 03 '22 at 02:44
  • @griffins I tried the above solution it works but the issue is there are multiple alert dialogues been overlayed one over the other throughout the completion of the progress bar see this: [Imgur](https://i.imgur.com/pdmTF53.gifv). – OddlyGhost May 03 '22 at 14:04

0 Answers0