Reputation: 51
I am new to Flutter and I am trying to load a Firebase Storage Image in a flutter application. But the build is failing with an exception. I tried the following way to load the image in a ListTile
. How can I fix this?
ListTile(
title: Text(record.date),
leading: CircleAvatar(
backgroundImage: FirebaseStorageImage(
'gs://project-12345.appspot.com/path/to/avatar_image.png'),
),
),
Following is the Exception that I am getting.
Compiler message:
/D:/sdks/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage_image-0.4.0/lib/firebase_storage_image.dart:54:24: Error: The method 'FirebaseStorageImage.load' has fewer positional arguments than those of overridden method 'ImageProvider.load'.
ImageStreamCompleter load(FirebaseStorageImage key) =>
^
/D:/sdks/flutter/packages/flutter/lib/src/painting/image_provider.dart:403:24: Context: This is the overridden method ('load').
ImageStreamCompleter load(T key, DecoderCallback decode);
^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
Upvotes: 2
Views: 959
Reputation: 412
Recommend like this:
StorageReference sr = FirebaseStorage.instance.ref();
String url = await sr.child('path').getDownloadURL();
Image.network(url);
Upvotes: 1
Reputation: 290
If you have the image already stored in Firebase storage you can display the image in your flutter application using the firebase generated access token for your image.
try
backgroundImage: NetworkImage(access_token_for_your_image),
If you haven't created the access token, you can do so by going to your image location in firebase storage and clicking on 'create new access token' under the option 'file location'. You can also generate one while uploading the image from your application by using the getDownloadURL()
function on your upload.
Upvotes: 2