Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I upload an image to firebase storage but i can't see image in firebase storage

First this is about my uploadImage code, I try to fix it again and again but doesn’t work

Future uploadImageFile() async
  {
    String fileName = DateTime.now().millisecondsSinceEpoch.toString();
    StorageReference storageReference = FirebaseStorage.instance.ref().child("Chat Images").child(fileName);

    StorageUploadTask storageUploadTask = storageReference.putFile(imageFile);
    StorageTaskSnapshot storageTaskSnapshot = await storageUploadTask.onComplete;

    storageTaskSnapshot.ref.getDownloadURL().then((downloadUrl){
      
      imageUrl = downloadUrl;
      setState(() {
        isLoading = false;
        onSendMessage(imageUrl, 1);
      });
    }, onError: (error){
      setState(() {
        isLoading = false;
      });
      Fluttertoast.showToast(msg: "Error: " + error);
    });
  }

And after in click upload image the result in terminal like this :

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: type 'PlatformException' is not a subtype of type 'String'
#0      ChatScreenState.uploadImageFile.<anonymous closure> (package:telegramchatapp/Pages/ChattingPage.dart:726:47)
#1      _rootRunUnary (dart:async/zone.dart:1436:47)
#2      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#3      _FutureListener.handleError (dart:async/future_impl.dart:178:22)
#4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:779:47)
#5      Future._propagateToListeners (dart:async/future_impl.dart:800:13)
#6      Future._completeError (dart:async/future_impl.dart:610:5)
#7      _completeOnAsyncError (dart:async-patch/async_patch.dart:276:13)
#8      StorageReference.getDownloadURL (package:firebase_storage/src/storage_reference.dart)
<asynchronous suspension>
      

I don’t know what to do.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The exception you show in your question comes from this line:

Fluttertoast.showToast(msg: "Error: " + error);

The error in here is not a string, so you can’t concatenate it to a string. What you want is:

Fluttertoast.showToast(msg: "Error: " + error.toString());

Or:

Fluttertoast.showToast(msg: "Error: $error");

That will then show you what the root cause of the upload failure is, so you can address that.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading