s3_cache_image 0.0.1 copy "s3_cache_image: ^0.0.1" to clipboard
s3_cache_image: ^0.0.1 copied to clipboard

Flutter library to load and cache S3 Images. Can also be used with placeholder and error widgets.

example/lib/main.dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:s3_cache_image/s3_cache_image.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  @override
  void initState() {
    setS3CachePath('/s3/cache/images/food/');
    super.initState();
  }

  Future<bool> clearDiskCachedImages() async {
    return clearS3Cache();
  }

  /// Return the disk cache directory size.
  Future<int> getDiskCachedImagesSize() async {
    return getS3CacheSize();
  }

  @override
  Widget build(BuildContext context) {
    final width = MediaQuery.of(context).size.width / 2;
    return Scaffold(
      appBar: AppBar(
        title: Text('S3CacheImage'),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.delete),
            onPressed: () async {
              print('delete cache');
              final success = await clearDiskCachedImages();
              if (success) {
                setState(() {});
              }
            },
          ),
          IconButton(
            icon: Icon(Icons.save),
            onPressed: () async {
              final size = await getDiskCachedImagesSize();
              print('CACHE SIZE $size');
            },
          )
        ],
      ),
      body: Container(
//        decoration: BoxDecoration(color: Colors.red),
          width: width,
          height: width,
          child: S3CachedImage(
              fit: BoxFit.cover,
              width: width,
              height: width,
              onExpired: (id) {
                final completer = Completer<String>()
                  ..complete('INSERT S3 URL HERE');
                return completer.future;
              },
              onDebug: (log) {
                print('LOG $log');
              },
              imageURL: 'INSERT S3 URL HERE',
              cacheId: 'INSERT CACHE ID HERE',
              errorWidget: Center(child: Text('ERROR')),
              placeholder: Center(child: Text('LOADING')))),
    );
  }
}
1
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Flutter library to load and cache S3 Images. Can also be used with placeholder and error widgets.

Homepage

License

MIT (LICENSE)

Dependencies

flutter, http, logging, path_provider

More

Packages that depend on s3_cache_image