Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made start of documentation #702

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "cached_network_image",
"sidebar": [
[
"CachedNetworkImage",
[
["Overview", "/"]
]
],
["CacheManager",
[
["Overview", "/cache-manager"],
["Caching rules", "/caching-rules"]
]
],
["OctoImage",
[
["Overview","/octo-image"]
]
]
]
}
1 change: 1 addition & 0 deletions docs/cache-manager.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
4 changes: 4 additions & 0 deletions docs/caching-rules.mdx
Original file line number Diff line number Diff line change
@@ -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.
49 changes: 49 additions & 0 deletions docs/index.mdx
Original file line number Diff line number Diff line change
@@ -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).
4 changes: 4 additions & 0 deletions docs/octo-image.mdx
Original file line number Diff line number Diff line change
@@ -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.