You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/widget/cached_image_wrapper.dart

78 lines
2.1 KiB

import 'dart:io';
import 'dart:math';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_luban/flutter_luban.dart';
enum ImageType {
normal,
// random, //随机
assets, //资源目录
}
class CachedImageWrapper extends StatelessWidget {
final String url;
final double width;
final double height;
final BoxFit fit;
final ImageType imageType;
CachedImageWrapper(
{@required this.url,
@required this.width,
@required this.height,
this.imageType: ImageType.normal,
this.fit: BoxFit.cover});
@override
Widget build(BuildContext context) {
return imageType == ImageType.normal
? CachedNetworkImage(
key: Key(url),
imageBuilder: (context, imageProvider) {
return Container(
width: width,
height: height,
decoration: BoxDecoration(
color: Colors.transparent,
image: DecorationImage(
image: imageProvider, fit: BoxFit.cover, scale: 1),
),
);
},
imageUrl: imageUrl,
placeholder: (_, __) => SizedBox(
width: width,
height: height,
child:
CupertinoActivityIndicator(radius: min(10.0, width / 3))),
errorWidget: (_, __, ___) => SizedBox(
width: width,
height: height,
child: Icon(
Icons.error_outline,
),
),
)
: SizedBox(
width: width,
height: height,
child: Image.asset(imageUrl),
);
}
String get imageUrl {
switch (imageType) {
// case ImageType.random:
// return ImageHelper.randomUrl(
// key: url, width: width.toInt(), height: height.toInt());
case ImageType.assets:
return "assets/images/" + url;
case ImageType.normal:
return url;
}
return url;
}
}