firebase_cached_image 0.3.0
firebase_cached_image: ^0.3.0 copied to clipboard
Cache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.
example/lib/main.dart
import 'dart:io';
import 'package:firebase_cached_image/firebase_cached_image.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Firebase Cached Image',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Cached Image Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Image(
image: FirebaseImageProvider(
url: FirebaseUrl("gs://bucket_f233/logo.jpg"),
options: CacheOptions(
source: Source.server,
shouldCache: true,
metadataRefreshInBackground: true,
),
),
frameBuilder: (_, child, frame, __) {
if (frame == null) return child;
return const CircularProgressIndicator();
},
),
),
);
}
temo() async {
final file = await FirebaseCacheManager.instance.getSingleFile(
url: FirebaseUrl("gs://bucket_f233/doc.docx"),
);
final bytes = await File("path/image").readAsBytes();
FirebaseCacheManager.instance.uploadAndCache(
ref: FirebaseStorage.instance.ref().child("logo.png"),
bytes: bytes,
// Use this callback for listening to upload events
uploadTaskCallback: (task) {
// task.snapshotEvents.listen((event) => print(event.bytesTransferred));
return task;
},
);
FirebaseCacheManager.instance.cacheOptions = CacheOptions(
shouldCache: false,
);
FirebaseCacheManager.instance.clearCache();
FirebaseCacheManager.instance.delete(
url: FirebaseUrl("gs://bucket_f233/logo.jpg"),
);
FirebaseCacheManager.instance.preCache(
url: FirebaseUrl("gs://bucket_f233/doc.docx"),
);
// print(
// file.fullLocalPath); // Cached file's path, can be used for sharing file
// print(file.rawData); // File's bytes (Uint8List)
}
}