cached_network_image 0.6.0-beta+1 copy "cached_network_image: ^0.6.0-beta+1" to clipboard
cached_network_image: ^0.6.0-beta+1 copied to clipboard

outdated

Flutter library to load and cache network images. Can also be used with placeholder and error widgets.

example/lib/main.dart

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.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: _gridView(),
    );
  }

  _testContent() {
    return 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),
              ),
            ),
          ],
        ),
      ),
    );
  }

  _gridView() {
    return new GridView.builder(
        itemCount: 250,
        gridDelegate:
            new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
        itemBuilder: (BuildContext context, int index) {
          return new CachedNetworkImage(
            imageUrl:
                "http://via.placeholder.com/${(index + 1)}x${(index % 100 + 1)}",
            placeholder: _loader(),
          );
        });
  }

  _loader() {
    return new Center(
      child: CircularProgressIndicator(),
    );
  }

  Widget _sizedContainer(Widget child) {
    return new SizedBox(
      width: 300.0,
      height: 150.0,
      child: new Center(
        child: child,
      ),
    );
  }
}
6.43k
likes
0
points
1.99M
downloads

Publisher

verified publisherbaseflow.com

Weekly Downloads

Flutter library to load and cache network images. Can also be used with placeholder and error widgets.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_cache_manager

More

Packages that depend on cached_network_image