-
Notifications
You must be signed in to change notification settings - Fork 3
/
cached_network_image_screen.dart
48 lines (46 loc) · 1.44 KB
/
cached_network_image_screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
class CachedNetworkImageScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Cached Network Image Demo'),
),
body: ListView(
children: <Widget>[
_buildCachedNetworkImage("https://picsum.photos/400/200", 200),
_buildCachedNetworkImage("https://", 200),
],
),
);
}
Widget _buildCachedNetworkImage(String url, double imageHeight) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: CachedNetworkImage(
imageUrl: url,
imageBuilder: (context, imageProvider) {
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image(
image: imageProvider,
fit: BoxFit.cover,
),
);
},
placeholder: (context, url) => Container(
height: imageHeight,
child: Center(child: CircularProgressIndicator())),
errorWidget: (context, url, error) => Container(
width: double.infinity,
height: imageHeight,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.black.withOpacity(0.1),
),
child: Icon(Icons.error)),
),
);
}
}