搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。