53 lines
1.5 KiB
Dart
Executable File
53 lines
1.5 KiB
Dart
Executable File
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
/*
|
|
* 显示网络图片 并加缓存
|
|
* */
|
|
|
|
class CustomNetworkImage extends StatelessWidget {
|
|
|
|
const CustomNetworkImage(
|
|
{required this.url, required this.defaultUrl, required this.width, required this.height, Key? key,
|
|
this.boxFit = BoxFit.cover})
|
|
: super(key: key);
|
|
final String url;
|
|
final String defaultUrl;
|
|
final double width;
|
|
final double height;
|
|
final BoxFit boxFit;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return url.isNotEmpty
|
|
? CachedNetworkImage(
|
|
width: width,
|
|
height: height,
|
|
fit: boxFit,
|
|
imageUrl: url,
|
|
imageBuilder: (BuildContext context, ImageProvider<Object> imageProvider) => Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: imageProvider,
|
|
fit: boxFit,
|
|
colorFilter: const ColorFilter.mode(
|
|
Colors.transparent, BlendMode.colorBurn)),
|
|
),
|
|
),
|
|
errorWidget: (BuildContext context, String url, Object error) => Image.asset(
|
|
defaultUrl,
|
|
width: width,
|
|
height: height,
|
|
fit: BoxFit.fill,
|
|
),
|
|
)
|
|
: Image.asset(
|
|
defaultUrl,
|
|
width: width,
|
|
height: height,
|
|
fit: BoxFit.fill,
|
|
);
|
|
}
|
|
}
|