firebase_image 0.1.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

🔥 Firebase Image Provider #

pub package

A cached Flutter ImageProvider for Firebase Cloud Storage image objects.

How to use #

Make sure you already have Firebase set up on all platforms you want to use this on.

Supply the FirebaseImage widget with the image's URI (e.g. gs://bucket123/userIcon123.jpg) and then put that in any widget that accepts an ImageProvider (most image related widgets will (e.g. Image, ImageIcon, etc.)). Please note that you do need the gs:// prefix currently.

See the below for example code.

How does it work? #

The code downloads the image (object) into memory as a byte array.

Unless disabled using the cacheRefreshStrategy: CacheRefreshStrategy.NEVER option, it gets the object's last update time from metadata (a millisecond precision integer timstamp) and uses that as a defacto version number. Therefore, any update to that remote object will result in the new version being downloaded.

The image byte array in memory then gets saved to a file in the temporary directory of the app and that location is saved in a persistant database. The OS can clean up this directory at any time however.

Metadata retrival is a 'Class B Operation' and has 50,000 free operations per month. After that, it is billed at $0.04 / 100,000 operations and so the default behaviour of cacheRefreshStrategy: CacheRefreshStrategy.BY_METADATA_DATE may incur extra cost if the object never changes. This makes this implementation a cost effective stratergy for caching as the entire object doesn't have to be transfered just to check if there have been any updates. Essentailly, any images will only need to be downloaded once per device.

Example #

import 'package:flutter/material.dart';
import 'package:firebase_image/firebase_image.dart';

class IconImage extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Firebase Image Provider example'),
      body: Image(
        image: FirebaseImage('gs://bucket123/userIcon123.jpg'),
        // Works with standard parameters, e.g.
        fit: BoxFit.fitWidth,
        width: 100,
        // ... etc.

To Do #

  • [x] Add examples to
  • [ ] Clear items from cache if they haven't been accessed after a certain amount of time (2 weeks?)
  • [ ] Add more documentation/comments
  • [ ] Create unit tests

Contributing #

If you want to contribute, please fork the project and play around there!

If you're stuck for ideas, check Issues or the above To Do list for inspiration.

Please check PRs and other peoples forks to see if anyone is working on something similiar to what you want to do.

Once you're ready, please submit a pull request.

[0.1.6] - 10/05/2020 #

  • Added ability to disable metadata (class B operations) requests for images (e.g. for images that will never change).

[0.1.5] - 26/12/2019 #

[0.1.4] - 27/11/2019 #

  • Added ability to get image as bytes.
  • Formatted test file.

[0.1.3] - 22/10/2019 #

  • Updated author information to match verified publisher account.
  • Formatted code.

[0.1.2] - 22/09/2019 #

  • Hash code implemented (allows for things like Hero widgets).

[0.1.1] - 22/09/2019 #

  • Database primary key bug fix.
  • Misc. bug fixes.

[0.1.0] - 22/09/2019 #

  • Added example.
  • Formatted code.

[0.0.1] - 22/09/2019 #

  • Can download, save and render images from Firebase Cloud Storage.
  • Basic caching system works but no object expiration time or read monitoring as of yet.


import 'package:flutter/material.dart';
import 'package:firebase_image/firebase_image.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Firebase Image Provider Demo',
      theme: ThemeData(
      home: MyHomePage(title: 'Firebase Image Provider example'),

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  void initState() {

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      body: Image(
        image: FirebaseImage(
          shouldCache: true, // The image should be cached (default: True)
          maxSizeBytes: 3000 * 1000, // 3MB max file size (default: 2.5MB)
          cacheRefreshStrategy: CacheRefreshStrategy.NEVER // Switch off update checking
        width: 100,

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  firebase_image: ^0.1.6

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:firebase_image/firebase_image.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Health suggestions

Format lib/src/cache_refresh_strategy.dart.

Run flutter format to format lib/src/cache_refresh_strategy.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
firebase_core ^0.4.3+1 0.4.5
firebase_storage ^3.1.0 3.1.6
flutter 0.0.0
path ^1.6.4 1.7.0
path_provider ^1.3.0 1.6.10
sqflite ^1.1.6+5 1.3.0+2 1.3.1-dev.1
Transitive dependencies
charcode 1.1.3
collection 1.14.12
file 5.1.0
firebase 7.3.0
firebase_core_platform_interface 1.0.4
firebase_core_web 0.1.1+2
flutter_web_plugins 0.0.0
http 0.12.1
http_parser 3.1.4
intl 0.16.1
js 0.6.1+1
matcher 0.12.6
meta 1.1.8
path_provider_linux 0.0.1+1
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
pedantic 1.9.0
platform 2.2.1
plugin_platform_interface 1.0.2
process 3.0.13
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
sqflite_common 1.0.1
stack_trace 1.9.3
string_scanner 1.0.5
synchronized 2.2.0
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
xdg_directories 0.1.0
Dev dependencies