57 lines
1.5 KiB
Dart
Executable File
57 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 {
|
|
final String url;
|
|
final String defaultUrl;
|
|
final double width;
|
|
final double height;
|
|
final BoxFit boxFit;
|
|
|
|
const CustomNetworkImage(
|
|
{Key? key,
|
|
required this.url,
|
|
required this.defaultUrl,
|
|
required this.width,
|
|
required this.height,
|
|
this.boxFit = BoxFit.cover})
|
|
: super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return url.isNotEmpty
|
|
? 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) => Image.asset(
|
|
defaultUrl,
|
|
width: width,
|
|
height: height,
|
|
fit: BoxFit.fill,
|
|
),
|
|
)
|
|
: Image.asset(
|
|
defaultUrl,
|
|
width: width,
|
|
height: height,
|
|
fit: BoxFit.fill,
|
|
);
|
|
}
|
|
}
|