s3_cache_image 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 35

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

getS3CacheSize();

Purging cache directory will return future

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 pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
39
Health:
Code health derived from static analysis. [more]
31
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
30
Overall:
Weighted score of the above. [more]
35
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms:

Low code quality prevents platform classification.

Health issues and suggestions

Fix lib/s3_cache_image.dart. (-68.52 points)

Analysis of lib/s3_cache_image.dart failed with 4 errors, 1 hint:

line 139 col 38: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.

line 140 col 32: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.

line 150 col 34: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.

line 397 col 9: The argument type 'Null Function(StringBuffer)' can't be assigned to the parameter type 'Iterable

line 397 col 31: This function has a return type of 'Iterable

Format lib/src/s3_cache_manager.dart.

Run flutter format to format lib/src/s3_cache_manager.dart.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Low code quality prevents platform classification.

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (http, path_provider).

Package is getting outdated. (-19.73 points)

The package was last published 62 weeks ago.

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

While nothing is inherently wrong with versions of 0.0.*, it might mean 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+2
logging ^0.11.3+1 0.11.3+2
path_provider ^0.4.1 0.4.1 1.4.4
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.7 1.1.8
path 1.6.4
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8