cached_network_image 0.4.1+1

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

Cached network image

pub package Donate

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

How to add

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

dependencies:
  cached_network_image: "^0.4.1"

Add it to your dart file:

import 'package:cached_network_image/cached_network_image.dart';

How to use

The CachedNetworkImage can be used directly or through the ImageProvider.

new CachedNetworkImage(
       imageUrl: "http://via.placeholder.com/350x150",
       placeholder: new CircularProgressIndicator(),
       errorWidget: new Icon(Icons.error),
     ),
new Image(image: new CachedNetworkImageProvider(url))

How it works

The cached network images stores and retrieves files using the flutter_cache_manager.

[0.4.1] - 2018-04-27

  • Improved error handling when a file could not be loaded.

[0.4.0] - 2018-04-14

  • Added optional headers.
  • Changed to Dart 2.0
  • Fixed bug when updating widget with new url

[0.3.0] - 2018-02-09

  • Added CachedNetworkImage with placeholder and error widgets.

[0.2.1] - 2018-01-08

  • Moved from OneFrameImageStreamCompleter to MultiFrameImageStreamCompleter.
  • Updated CacheManager dependency for critical bug fix.

[0.2.0] - 2017-12-29

  • Breaking change Removed CachedNetworkImage. From now on only the ImageProvider is supported. For a placeholder use FadeInImage. See also "Fallback for Network Images".
  • Moved CacheManager to a separate library for a more generic purpose.

[0.1.0] - 2017-12-21

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version. Instructions can be found here.

[0.0.2] - 10 December 2017

Added an ImageProvider and improved documentation

[0.0.1] - 2 December 2017

Initial release, should be polished

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'CachedNetworkImage Demo',
      theme: new ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or press Run > Flutter Hot Reload in IntelliJ). Notice that the
        // counter didn't reset back to zero; the application is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'CachedNetworkImage'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;
  MyHomePage({this.title});

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: new Text(title),
      ),
      body:
      new SingleChildScrollView(child:
      new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[

            _sizedContainer(
              new Image(
                image: new CachedNetworkImageProvider("http://via.placeholder.com/350x150"),
              ),
            ),

            _sizedContainer(
              new CachedNetworkImage(
                imageUrl: "http://via.placeholder.com/200x150",
              ),
            ),

            _sizedContainer(
              new CachedNetworkImage(
                imageUrl: "not a valid uri",
                placeholder: new CircularProgressIndicator(),
                errorWidget: new Icon(Icons.error),
              ),
            ),

            _sizedContainer(
              new CachedNetworkImage(
                imageUrl: "http://via.placeholder.com/350x200",
                placeholder: new CircularProgressIndicator(),
                errorWidget: new Icon(Icons.error),
                fadeOutDuration: new Duration(seconds: 1),
                fadeInDuration: new Duration(seconds: 3),
              ),
            ),

          ],
        ),
      ),
      ),
    );
  }

  Widget _sizedContainer(Widget child) {
    return new SizedBox(
      width: 300.0,
      height: 150.0,
      child: new Center(
        child: child,
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  cached_network_image: "^0.4.1+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:cached_network_image/cached_network_image.dart';
  
Version Uploaded Documentation Archive
0.4.1+1 May 1, 2018 Go to the documentation of cached_network_image 0.4.1+1 Download cached_network_image 0.4.1+1 archive
0.4.1 Apr 27, 2018 Go to the documentation of cached_network_image 0.4.1 Download cached_network_image 0.4.1 archive
0.4.0 Apr 14, 2018 Go to the documentation of cached_network_image 0.4.0 Download cached_network_image 0.4.0 archive
0.3.0 Feb 9, 2018 Go to the documentation of cached_network_image 0.3.0 Download cached_network_image 0.3.0 archive
0.2.1 Jan 8, 2018 Go to the documentation of cached_network_image 0.2.1 Download cached_network_image 0.2.1 archive
0.2.0 Dec 29, 2017 Go to the documentation of cached_network_image 0.2.0 Download cached_network_image 0.2.0 archive
0.1.0 Dec 21, 2017 Go to the documentation of cached_network_image 0.1.0 Download cached_network_image 0.1.0 archive
0.0.2 Dec 10, 2017 Go to the documentation of cached_network_image 0.0.2 Download cached_network_image 0.0.2 archive
0.0.1 Dec 9, 2017 Go to the documentation of cached_network_image 0.0.1 Download cached_network_image 0.0.1 archive
0.4.0-rc.1 Mar 24, 2018 Go to the documentation of cached_network_image 0.4.0-rc.1 Download cached_network_image 0.4.0-rc.1 archive

All 11 versions...

Analysis

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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
98 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
99
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • Package is pre-v1 release.

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
flutter_cache_manager ^0.1.1 0.1.1
Transitive dependencies
async 2.0.7
charcode 1.1.2
collection 1.14.6 1.14.10
convert 2.0.1
crypto 2.0.5
http 0.11.3+16 0.11.3+17
http_parser 3.1.2
meta 1.1.5
path 1.6.0 1.6.1
path_provider 0.4.1
shared_preferences 0.4.2
sky_engine 0.0.99
source_span 1.4.0
string_scanner 1.0.2
synchronized 1.5.0+1
typed_data 1.1.5
uuid 0.5.3 1.0.1
vector_math 2.0.6 2.0.7
Dev dependencies
test ^0.12.0