From 14dbe4e3c34d66174513505ffd5e584e9a8ea0a5 Mon Sep 17 00:00:00 2001 From: Rene Floor Date: Tue, 11 Jan 2022 17:23:24 +0100 Subject: [PATCH] Made start of documentation --- docs.json | 22 +++++++++++++++++++ docs/cache-manager.mdx | 1 + docs/caching-rules.mdx | 4 ++++ docs/index.mdx | 49 ++++++++++++++++++++++++++++++++++++++++++ docs/octo-image.mdx | 4 ++++ 5 files changed, 80 insertions(+) create mode 100644 docs.json create mode 100644 docs/cache-manager.mdx create mode 100644 docs/caching-rules.mdx create mode 100644 docs/index.mdx create mode 100644 docs/octo-image.mdx diff --git a/docs.json b/docs.json new file mode 100644 index 00000000..c1d0d572 --- /dev/null +++ b/docs.json @@ -0,0 +1,22 @@ +{ + "name": "cached_network_image", + "sidebar": [ + [ + "CachedNetworkImage", + [ + ["Overview", "/"] + ] + ], + ["CacheManager", + [ + ["Overview", "/cache-manager"], + ["Caching rules", "/caching-rules"] + ] + ], + ["OctoImage", + [ + ["Overview","/octo-image"] + ] + ] + ] +} \ No newline at end of file diff --git a/docs/cache-manager.mdx b/docs/cache-manager.mdx new file mode 100644 index 00000000..30404ce4 --- /dev/null +++ b/docs/cache-manager.mdx @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/docs/caching-rules.mdx b/docs/caching-rules.mdx new file mode 100644 index 00000000..c160c5ae --- /dev/null +++ b/docs/caching-rules.mdx @@ -0,0 +1,4 @@ +# Caching rules + +It uses [cache-control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) headers to know if the cache is outdated (max-age and eTag). +If it is outdated the cached version is shown directly and the server is requested for an update. If the server sends a new image it updates the image directly. \ No newline at end of file diff --git a/docs/index.mdx b/docs/index.mdx new file mode 100644 index 00000000..96d8ca1f --- /dev/null +++ b/docs/index.mdx @@ -0,0 +1,49 @@ +# Cached network image +## How to use +The CachedNetworkImage can be used directly or through the ImageProvider. +Both the CachedNetworkImage as CachedNetworkImageProvider have minimal support for web. It currently doesn't include caching. + +With a placeholder: +```dart +CachedNetworkImage( + imageUrl: "http://via.placeholder.com/350x150", + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => Icon(Icons.error), + ), + ``` + + Or with a progress indicator: + ```dart +CachedNetworkImage( + imageUrl: "http://via.placeholder.com/350x150", + progressIndicatorBuilder: (context, url, downloadProgress) => + CircularProgressIndicator(value: downloadProgress.progress), + errorWidget: (context, url, error) => Icon(Icons.error), + ), + ``` + + +````dart +Image(image: CachedNetworkImageProvider(url)) +```` + +When you want to have both the placeholder functionality and want to get the imageprovider to use in another widget you can provide an imageBuilder: +```dart +CachedNetworkImage( + imageUrl: "http://via.placeholder.com/200x150", + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, + colorFilter: + ColorFilter.mode(Colors.red, BlendMode.colorBurn)), + ), + ), + placeholder: (context, url) => CircularProgressIndicator(), + errorWidget: (context, url, error) => Icon(Icons.error), +), +``` + +## How it works +The cached network images stores and retrieves files using the [flutter_cache_manager](https://pub.dartlang.org/packages/flutter_cache_manager). \ No newline at end of file diff --git a/docs/octo-image.mdx b/docs/octo-image.mdx new file mode 100644 index 00000000..a368cb18 --- /dev/null +++ b/docs/octo-image.mdx @@ -0,0 +1,4 @@ +# OctoImage + +CachedNetworkImage uses OctoImage under the hood. You can also use OctoImage directly to use the same placeholder logic for +both cached and non-cached images. \ No newline at end of file