0

I would like do display images stored on Firbase storage in my Flutter app but I'm dealing with this problem. I followed the instructions on this answer but my ref() always comes like this:

print

I created this method only to test, and when I try get the DownloadURL the flutter throws a exception:

/flutter ( 4664): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ I/flutter ( 4664): The following ArgumentError was thrown resolving an image codec: I/flutter ( 4664): Invalid argument(s): No host specified in URI file:///Instance%20of%20'Future'

  void _locateFile() async{
    final ref = FirebaseStorage.instance
        .ref()
        .child('avatars')
        .child('simples')
        .child('woman1.png');

    var url = Uri.parse(await ref.getDownloadURL() as String);
    print(url);
  }
}

Here is the image info:

info

So, if someone can help me, I'll be very happy :)

Dennis Alund
  • 2,916
  • 1
  • 13
  • 34
Éowyn
  • 187
  • 3
  • 17
  • I am unable to reproduce the problem based on the code you shared. I posted the code and its output below. Are you sure your Firebase project is correctly initialized in your app? – Frank van Puffelen Dec 30 '18 at 06:55

2 Answers2

1

I imagine you want to remove the the as String cast. Right now you're applying it to the result of ref.getDownloadURL(). That's certainly not correct. You want to await the future that it returns, not a string version of that object. Notice that what you're trying to parse with Uri.parse() is "file:///Instance%20of%20'Future'" - see the words "Instance of Future"?

Also you may way to temporarily remove Uri.parse() and just focus on understanding the value contained in the future returned by getDownloadUrl(). Once you understand the return value, and can see that it contains what you want, then try to do something else with it.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • I replaced the last line with `String s = await ref.getDownloadURL();` and worked fine. Thanks! – Éowyn Dec 30 '18 at 10:07
1

I just tried to reproduce the problem, but somehow this code works fine for me:

var earringsRef = FirebaseStorage.instance.ref().child("EARRINGS.JPG");
var downloadURL = await earringsRef.getDownloadURL();
print(downloadURL);

var url = Uri.parse(await earringsRef.getDownloadURL() as String);
print(url);

Both lines print the same URL:

flutter: https://firebasestorage.googleapis.com/v0/b/project-8080059325282098184.appspot.com/o/EARRINGS.JPG?alt=media&token=0958acfc-3545-4af4-b38b-27a7ae38b20f

flutter: https://firebasestorage.googleapis.com/v0/b/project-8080059325282098184.appspot.com/o/EARRINGS.JPG?alt=media&token=0958acfc-3545-4af4-b38b-27a7ae38b20f

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807