-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathimage.dart
More file actions
52 lines (47 loc) · 1.35 KB
/
image.dart
File metadata and controls
52 lines (47 loc) · 1.35 KB
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
50
51
52
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:fun_android/config/app_store.dart';
import 'package:fun_android/config/resource_mananger.dart';
enum ImageType {
normal,
random, //随机
assets, //资源目录
}
class WrapperImage extends StatelessWidget {
final String url;
final double width;
final double height;
final BoxFit fit;
final ImageType imageType;
WrapperImage(
{@required this.url,
@required this.width,
@required this.height,
this.imageType: ImageType.normal,
this.fit: BoxFit.cover});
@override
Widget build(BuildContext context) {
return CachedNetworkImage(
imageUrl: imageUrl,
width: width,
height: height,
placeholder: (_, __) =>
ImageHelper.placeHolder(width: width, height: height),
errorWidget: (_, __, ___) =>
ImageHelper.error(width: width, height: height),
fit: fit,
);
}
String get imageUrl {
switch (imageType) {
case ImageType.random:
return ImageHelper.randomUrl(
key: url, width: width.toInt(), height: height.toInt());
case ImageType.assets:
return ImageHelper.wrapAssets(url);
case ImageType.normal:
return url;
}
return url;
}
}