35 lines
1.0 KiB
Dart
35 lines
1.0 KiB
Dart
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 {
|
|
final String url;
|
|
final double width;
|
|
final double height;
|
|
final BoxFit boxFit;
|
|
const CustomNetworkImage({Key? key, required this.url, required this.width, required this.height, this.boxFit=BoxFit.cover}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CachedNetworkImage(
|
|
width: width,
|
|
height: height,
|
|
fit: boxFit,
|
|
imageUrl: url,
|
|
imageBuilder: (context, imageProvider) => Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: imageProvider,
|
|
fit: boxFit,
|
|
colorFilter: const ColorFilter.mode(Colors.transparent, BlendMode.colorBurn)),
|
|
),
|
|
),
|
|
errorWidget: (context, url, error) => Icon(Icons.error,size: 40.sp)
|
|
);
|
|
}
|
|
}
|