Skip to content

Commit

Permalink
Clear issue #1, #2, #3
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstj committed Sep 7, 2018
1 parent b13298e commit 350f92f
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 113 deletions.
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

# 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].


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

This package is based from [https://github.com/renefloor/flutter_cached_network_image]
## How to add

Add this to your package's pubspec.yaml file:
Expand All @@ -19,16 +17,39 @@ import 'package:s3_cache_image/s3_cache_image.dart';
```

## How to use
The S3ImageCache can be used directly or through the ImageProvider.

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();
```




2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# example

A new Flutter project.
An example for how to use s3_cache_image pacakage

## Getting Started

Expand Down
45 changes: 16 additions & 29 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'dart:async';
import 'dart:io';

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

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

Expand All @@ -26,32 +23,20 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {

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

Future<bool> clearDiskCachedImages() async {
final tempDir = await getTemporaryDirectory();
final cachePath = tempDir.path + '/images';
final cacheDir = Directory(cachePath);
try {
await cacheDir.delete(recursive: true);
} catch (_) {
return false;
}
return true;
return clearS3Cache();
}

/// Return the disk cache directory size.
Future<int> getDiskCachedImagesSize() async {
final tempDir = await getTemporaryDirectory();
final cachePath = tempDir.path + '/images';
final cacheDir = Directory(cachePath);

print('${cacheDir.path}');
var size = 0;
try {
cacheDir.listSync().forEach((var file) => size += file.statSync().size);
return size;
} catch (_) {
return null;
}
return getS3CacheSize();
}

@override
Expand Down Expand Up @@ -90,14 +75,16 @@ class _HomePageState extends State<HomePage> {
height: width,
onExpired: (id) {
final completer = Completer<String>()
..complete('INSERT S3 URL');
..complete('INSERT S3 URL HERE');
return completer.future;
},
// onExpired: null,
imageURL: 'INSERT S3 URL',
cacheId: '123-456-789',
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')))),
placeholder: Center(child: Text('LOADING')))),
);
}
}
Loading

0 comments on commit 350f92f

Please sign in to comment.