Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) => MaterialApp(
title: 'CachedNetworkImage Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: MyHomePage(),
);
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text('CachedNetworkImage')),
body: _testContent(),
);
_testContent() {
return SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CachedNetworkImage(
placeholder: (context, url) =>
CircleAvatar(radius: 200, backgroundColor: Colors.purple),
imageBuilder: (context, provider) {
print('image builder');
return CircleAvatar(
backgroundImage: provider,
radius: 200,
);
},
imageUrl:
'https://upload.wikimedia.org/wikipedia/en/thumb/4/4a/Dr_John_Zoidberg.png/200px-Dr_John_Zoidberg.png',
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment