s3_cache_image 0.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 58

Cached network image

A flutter library to show image from S3 repository and keep them in the cache directory.

This package is based from [https://github.com/renefloor/flutter_cached_network_image]. With how to download and show images from S3 repository in mind.

How to add

Add this to your package's pubspec.yaml file:

dependencies:
  s3_cache_image: "^0.0.1"

Add it to your dart file:

import 'package:s3_cache_image/s3_cache_image.dart';

How to use

S3ImageCache can be used directly or through the ImageProvider.

S3CachedImage(
              fit: BoxFit.cover,
              width: width,
              height: width,
              onExpired: null,
              onDebug: null,
              imageURL: 'INSERT S3 URL HERE',
              cacheId: 'INSERT CACHE ID HERE',
              errorWidget: Center(child: Text('ERROR')),
              placeholder: Center(child: Text('Loading')))

Files stored in system temporary folder, so it can be cleared automatically by OS if necessary.

Set directory path:

setS3CachePath('/s3/cache/newImage/hello/');

Get cache size will return future<int>:

getS3CacheSize();

Purging cache directory will return future<bool>:

clearS3Cache();

[0.0.1] - 24 August 2018

Initial release, should be polished

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')))),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  s3_cache_image: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:s3_cache_image/s3_cache_image.dart';
  
Version Uploaded Documentation Archive
0.0.1 Sep 10, 2018 Go to the documentation of s3_cache_image 0.0.1 Download s3_cache_image 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
http ^0.11.3+16 0.11.3+17 0.12.0
logging ^0.11.3+1 0.11.3+2
path_provider ^0.4.1 0.4.1
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
vector_math 2.0.8