Firebase Cloud Storage에 저장된 이미지용 캐시된 ImageProvider를 제공하는 플러터 패키지입니다. 캐싱, 오류 상태 및 로딩 인디케이터를 자동으로 처리하여 원격 이미지의 로드와 표시를 간소화합니다. Firebase 스토리지 시스템과 원활하게 작동하도록 설계되어 봇일러플레이트 코드를 줄이고 중복 다운로드를 방지하여 성능을 향상시킵니다. 가볍고 복잡한 설정 없이 기존 플러터 앱에 직접 통합할 수 있습니다.
사용 사례
Firebase Cloud Storage에서 이미지 로드
성능 향상을 위해 원격 이미지를 캐시하는 것
플레이스홀더 또는 오류 이미지 표시
Flutter의 Image 위젯과 통합
캐싱을 통한 네트워크 요청 감소
주요 기능
자동 이미지 캐싱
로딩, 오류 및 자리 표시자 상태 지원
Firebase Cloud Storage와의 원활한 통합
필요한 최소한의 보일러플레이트
효율적인 메모리 및 디스크 사용
적합한 대상
이미지에 Firebase Cloud Storage를 사용하는 앱
간단한 이미지 로딩을 찾는 개발자
오프라인 이미지 접근이 필요한 프로젝트
고주파 이미지 표시 앱
성능과 신뢰성을 우선시하는 팀
고려 사항
Firebase Cloud Storage 설정이 필요합니다
Firebase 호스팅 이미지에 한정
내장된 이미지 변환 없음
모든 이미지 형식을 지원하지 않습니다
Firebase SDK 사용 가능 여부에 따라 다름
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
🔥 Firebase Image Provider
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';
classIconImageextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
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.
),
);
}
}