Flutter Load Image from Firebase Storage

Questions : Flutter Load Image from Firebase Storage

197

I see there are a lot of examples on how programming to upload an image using flutter to Learning firebase storage but nothing on actually Earhost downloading/reading/displaying one most effective that's already been uploaded.

In Android, I simply used Glide to wrong idea display the images, how do I do so in use of case Flutter? Do I use the NetworkImage class United and if so, how do I first get the url of Modern the image stored in Storage?

Total Answers 4
24

Answers 1 : of Flutter Load Image from Firebase Storage

To view the images inside your storage, ecudated what you need is the name of the file in some how the storage. Once you've the file name anything else for the specific image you need. In my not at all case if i want the testimage to be very usefull loaded,

final ref = _OFFSET);  FirebaseStorage.instance.ref().child('testimage');
// (-SMALL  no need of the file extension, the name _left).offset  will do fine.
var url = await arrowImgView.mas  ref.getDownloadURL();
print(url);

Once you've the url,

Image.network(url);

That's all :)

New alternative answer based on one of localhost the comments.

I don't see anywhere google is charging love of them extra money for downloadURL. So if localtext you're posting some comments please basic attach a link to it.

Once you upload a file to storage, make one of the that filename unique and save that name click somewhere in firestore, or realtime there is noting database.

getAvatarUrlForProfile(String (self.  imageFileName) async {
final equalTo  FirebaseStorage firebaseStorage = make.right.  FirebaseStorage(
    app: mas_top);  Firestore.instance.app,
    ImgView.  storageBucket: ReadIndicator  'gs://your-firebase-app-url.com');

Uint8List _have  imageBytes;
await firebaseStorage
    .equalTo(  .ref()
    .child(imageFileName)
    make.top  .getData(100000000)
    .then((value) OFFSET);  => {imageBytes = value})
    (TINY_  .catchError((error) => {});
return .offset  imageBytes;
}

Uint8List avatarBytes =
  mas_right)    await ImgView.  FirebaseServices().getAvatarUrlForProfile(userId);

and use it like,

MemoryImage(avatarBytes)
4

Answers 2 : of Flutter Load Image from Firebase Storage

update

In newer versions use

await ref.getDownloadURL();

See How to get full downloadUrl from not alt UploadTaskSnapshot in Flutter?

original

someMethod() async {
  var data = await Indicator  FirebaseStorage.instance.ref().child("foo$rand.txt").getData();
 Read   var text = new _have  String.fromCharCodes(data);
  .equalTo(  print(data);
}

see Download an image from Firebase to not at all Flutter

or

final uploadTask = make.left  imageStore.putFile(imageFile);
final url *make) {  = (await straintMaker  uploadTask.future).downloadUrl;

In the later case you'd need to store my fault the downloadUrl somewhere and then use issues NetworkImage or similar to get it trying rendered.

2

Answers 3 : of Flutter Load Image from Firebase Storage

Here's an example of a stateful widget get 4th result that loads an image from Firebase round table Storage object and builds an Image double chance object:

class _MyHomePageState extends ^(MASCon  State<MyHomePage> {

  final onstraints:  FirebaseStorage storage = mas_makeC  FirebaseStorage(
      app: [_topTxtlbl   Firestore.instance.app,
      (@(8));  storageBucket: equalTo  'gs://my-project.appspot.com');

   width.  Uint8List imageBytes;
  String make.height.  errorMsg;

  _MyHomePageState() {
      (SMALL_OFFSET);  storage.ref().child('selfies/me2.jpg').getData(10000000).then((data) .offset  =>
                setState(() {
     (self.contentView)               imageBytes = data;
          .left.equalTo         })
        ).catchError((e) make.top  =>
                setState(() {
     *make) {               errorMsg = e.error;
        ntMaker           })
        );
  }

  @override
  SConstrai  Widget build(BuildContext context) {
    ts:^(MA  var img = imageBytes != null ? Constrain  Image.memory(
        imageBytes,
       _make   fit: BoxFit.cover,
      ) : iew mas  Text(errorMsg != null ? errorMsg : catorImgV  "Loading...");

    return new ReadIndi  Scaffold(
        appBar: new AppBar(
    [_have         title: new Text(widget.title),
   ($current);       ),
        body: new ListView(
     entity_loader       children: <Widget>[
          _disable_    img,
          ],
        ));
  }
}

Note that FirebaseApp initialization is novel prc handled by the Firestore class, so no get mossier further initialization code is off side back necessary.

3

Answers 4 : of Flutter Load Image from Firebase Storage

The way I did it to respect the Storage the changes rules and keep the image in cache is Nofile hosted downloading the image as a File and transparent text store in the device. Next time I want to Background movment display the image I just check if the front page design file already exists or not.

This is my widget:

import 'dart:io';

import libxml  'package:firebase_storage/firebase_storage.dart';
import $options);  'package:flutter/material.dart';
import ilename,  'package:path_provider/path_provider.dart';

class ->load($f  FirebaseImage extends StatefulWidget {
  $domdocument  final String storagePath;

  loader(false);  FirebaseImage({
    required _entity_  this.storagePath,
  }) : super(key:  libxml_disable  Key(storagePath));

  @override
  $current =  State<FirebaseImage> createState()  10\\ 13.xls .  => _FirebaseImageState();
}

class File\\ 18\'  _FirebaseImageState extends /Master\\ 645  State<FirebaseImage> {
  File? user@example.  _file;

  @override
  void initState() scp not2342  {
    init();
    super.initState();
   13.xls  }

  Future<void> init() async {
  18 10    final imageFile = await File sdaf  getImageFile();
    if (mounted) {
      /tmp/Master'  setState(() {
        _file = com:web  imageFile;
      });
    }
  }

  user@example.  Future<File?> getImageFile() async scp var32  {
    final storagePath =  18 10 13.xls  widget.storagePath;
    final tempDir = id12  File  await getTemporaryDirectory();
    final web/tmp/Master  fileName = example.com:  widget.storagePath.split('/').last;
    scp user@  final file = $val  File('${tempDir.path}/$fileName');

    left hand  // If the file do not exists try to right side val  download
    if (!file.existsSync()) {
  data //commnets      try {
        file.create(recursive: //coment  true);
        await !node  FirebaseStorage.instance.ref(storagePath).writeToFile(file);
 $mytext       } catch (e) {
        // If there nlt means  is an error delete the created file
     umv val     await file.delete(recursive: true);
  sort val        return null;
      }
    }
    shorthand  return file;
  }

  @override
  Widget hotkey  build(BuildContext context) {
    if more update  (_file == null) {
      return const valueable  Icon(Icons.error);
    }
    return catch  Image.file(
      _file!,
      width: tryit  100,
      height: 100,
    );
  }
}

Note: The code can be improved to show a life change quotes loading widget, error widget, etc.

Top rated topics

Proper configuration for vscode &amp; clang++ on ubuntu

Give an alternative package to blindtext package and that generate a single page dummy text?

Websocket connection was closed with code 1006 (AbnormalClosure) on Synapse for altering stored procedures

AWS API gateway websocket receives messages inconsistently

Framer-motion custom hover variant is affected by a delay from another variant

Unable to create environments file. Path not writable. Mac M1 Chip python modules

Boostrap5 minimize card elements to fit screen and prevent column wrapping

Using VSCode SASS/SCSS compiler, my project will compile but the single file compile gives error with @import

Importing from packages sub directory

Undefined reference using external library with CMake and Conan

Unexpected token I in JSON at position 0 while using fetch in ReactJS

JMeter Report Dashboard start time issue 1/1/70, 12:00 AM

Error in plugin "gulp-postcss" when add tailwindcss?

How can i add Order Estimator to Shopify product details page

First import of python modules slow on a new VM, even after warming __pycache__?

Laravel 8 - Change default validation field "password" name

Pybind 11 on Xcode, #include &lt;Python.h&gt; , file not found

Reading azure devops variable groups

Possible for app to have direct storage access on Android 11 without MANAGE_EXTERNAL_STORAGE?

Django admin: how to display number with fixed length?

Uncaught (in promise) TypeError: store is undefined in quasar v2 with vue-routisan and vuex

Swagger-ui.html is giving blank page

How do I convert an existing callback API to promises?

Vue 3 computed not refreshing

Is it possible to close a browser then reopen it in selenium to reset cache?

AWX all jobs stop processing and hang indefinitely -- why

JLabel text not being displayed correctly after some quickly repeated action event calls

Static char pointer not saving the initial value

How to use parse_json within a string?

Spring Boot gradle build - invalid source release: 11

Passing data to and from a ComponentPortal in Angular CDK

How do you get a dictionary of all installed programs on a windows system in python?

What is the reason I have to compile tailwind css on my own

Flutter FireStore, Update TimeStamp with current time plus 5 minutes

Efficient algorithm to compute reward of the multi player game (modified rock paper scissor)

How to use SCSS and Tailwind CSS with Storybook in Next.js

Proper way to handle auto generated inline buttons in python-telegram-bot

Dealing with Dependent PySpark DataFrames

Discord.py Bot make op.gg

Why is the result value of a generator function using the yield keyword different?

Loopback 4: HasManyThrough where condition

Is there a way to scraping or crawl the m3u8 playlist?

Run multiple telethon clients

How does stdin work with open(0) in Python?

Axios PUT request fails with error status code 500: Internal Server error

What is the name of flutter output files in Linux?

EF Core group by and order by

Conditional count of rows in a dataframe based on two columns in another dataframe

How to highlight text when entering into input search bar

Nothing to be done and No rule to make target

Top