Flutter Package : Cache Network Image

Flutter Package : Cache Network Image

pubspec.yaml

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

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  final String title = "Cache Network Image";
  final Color bgColor = Colors.green;
  final Color fgColor = Colors.white;
  final IconData icLogo = Icons.star_border;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: title,
      home: Scaffold(
        backgroundColor: fgColor,
        appBar: new AppBar(
          backgroundColor: bgColor,
          leading: Icon(icLogo),
          title: Text(title),
        ),
        body: _MyImage(context),
      ),
    );
  }

  Widget _MyImage(BuildContext context) {
    return Center(
      child: CachedNetworkImage(
        imageUrl: "http://flutter.id/wp-content/uploads/2019/09/Logofluttermeetap-e1567860579991.png",
        imageBuilder: (context, imageProvider) => Container(
          width: 300,
          height: 200,
          decoration: BoxDecoration(
            image: DecorationImage(
                image: imageProvider,
                fit: BoxFit.contain,
            ),
          ),
        ),
        placeholder: (context, url) => CircularProgressIndicator(),
        errorWidget: (context, url, error) => Icon(Icons.error),
      ),
    );
  }
}

Flutter Developer