firebase_cached_image 0.2.0 copy "firebase_cached_image: ^0.2.0" to clipboard
firebase_cached_image: ^0.2.0 copied to clipboard

outdated

Cache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.

example/lib/main.dart

import 'dart:typed_data';

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(
            firebaseUrl: "gs://bucket_f233/logo.jpg",
            options: CacheOptions(
              source: Source.server,
            ),
          ),
          frameBuilder: (_, child, frame, __) {
            if (frame == null) return child;

            return const CircularProgressIndicator();
          },
        ),
      ),
    );
  }

  Future<Uint8List?> getDocument() async {
    await FirebaseCachedImage.initialise();
    FirebaseCachedImage.instance.cacheOptions = CacheOptions(
      shouldCache: false,
    );

    //if both ref and firebaseUrl are passed then ref will be used.
    return await FirebaseCachedImage.instance.get(
      firebaseUrl: "gs://bucket_f233/doc.pdf",
      // optional
      options: CacheOptions(
        source: Source.cacheServerByMetadata,
        metadataRefreshInBackground: false,
      ),
      // Can also pass ref
      ref: FirebaseStorage.instance.ref().child("doc.pdf"),
    );
  }
}
32
likes
0
pub points
91%
popularity

Publisher

unverified uploader

Cache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

firebase_core, firebase_storage, flutter, path, path_provider, sqflite, uuid

More

Packages that depend on firebase_cached_image