forked from TheAlphamerc/flutter_twitter_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_image.dart
49 lines (46 loc) · 1.32 KB
/
cache_image.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
49
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_twitter_clone/helper/constant.dart';
class CacheImage extends StatelessWidget {
const CacheImage({
Key? key,
this.path,
this.fit = BoxFit.contain,
this.errorWidget,
}) : super(key: key);
final String? path;
final BoxFit fit;
final Widget? errorWidget;
Widget customNetworkImage(String? path, {BoxFit fit = BoxFit.contain}) {
return CachedNetworkImage(
fit: fit,
imageUrl: path ?? Constants.dummyProfilePic,
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: fit,
),
),
),
placeholderFadeInDuration: const Duration(milliseconds: 500),
placeholder: (context, url) => Container(
color: const Color(0xffeeeeee),
),
cacheKey: path,
errorWidget: (context, url, error) =>
errorWidget ??
Container(
color: const Color(0xffeeeeee),
child: Icon(
Icons.error,
color: Colors.grey[700],
),
),
);
}
@override
Widget build(BuildContext context) {
return customNetworkImage(path, fit: fit);
}
}