搜索插件、代码仓与 APP 分类

插件详情v1.1.1

firebase_image

用于 Firebase Cloud Storage 图像对象的缓存 Flutter ImageProvider。

近 30 天下载
158
喜欢数
135
Pub 分数
60

安装插件

flutter pub add firebase_image

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,为存储在 Firebase Cloud Storage 中的图像提供缓存 ImageProvider。它通过自动处理缓存、错误状态和加载指示器,简化了远程图像的加载和显示。专为与 Firebase 存储系统无缝协作而设计,减少了样板代码,并通过避免重复下载来提升性能。该包轻量级,可直接集成到现有的 Flutter 应用中,无需复杂设置。

适合场景

  • 从 Firebase Cloud Storage 加载图片
  • 缓存远程图片以提高性能
  • 显示占位符或错误图像
  • 与 Flutter 的 Image 小部件集成
  • 通过缓存减少网络请求

主要特点

  • 自动图像缓存
  • 支持加载、错误和占位符状态
  • 与 Firebase Cloud Storage 的无缝集成
  • 所需的样板代码最少
  • 高效的内存和磁盘使用

适合对象

  • 使用 Firebase Cloud Storage 存储图片的应用
  • 寻求简单图像加载的开发者
  • 需要离线图像访问的项目
  • 高频图像显示的应用程序
  • 注重性能和可靠性的团队

使用建议

  • 需要 Firebase Cloud Storage 设置
  • 仅限 Firebase 托管的图片
  • 无内置图像转换
  • 不支持所有图像格式
  • 依赖 Firebase SDK 的可用性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

🔥 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 {
  @override
  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 pub.dev
  • [ ] 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.

所属分类

依赖

依赖清单 5 项

源码仓库

使用此插件的项目

暂无相关数据。