fix: 缺省图片添加
This commit is contained in:
1 parent
9e10608245
commit
a6b0a2ae95
7 files changed
+183
-26
No files matched your search
@@ -23,6 +23,9 @@ class ConstImg {
|
||||
static const String noworkImg = "assets/common/nowork_img.png";
|
||||
// applogo
|
||||
static const String appLogo = "assets/common/applogo.png";
|
||||
// space_img_h
|
||||
static const String spaceImgH = "assets/common/space_img_h.png";
|
||||
static const String spaceImgW = "assets/common/space_img_w.png";
|
||||
|
||||
|
||||
static const String homeBg = "assets/imgs/home_bg.png";
|
||||
@@ -137,6 +140,7 @@ class HelpImg {
|
||||
BoxShape? shape,
|
||||
BorderRadius? borderRadius,
|
||||
Widget? errorWidget,
|
||||
bool isWidth = false,
|
||||
}) {
|
||||
return ClipRRect(
|
||||
borderRadius: borderRadius ?? BorderRadius.circular(3),
|
||||
@@ -147,6 +151,7 @@ class HelpImg {
|
||||
height: height,
|
||||
shape: shape,
|
||||
errorWidget: errorWidget,
|
||||
isWidth: isWidth
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -161,6 +166,7 @@ class HelpImg {
|
||||
BoxShape? shape,
|
||||
BorderRadius? borderRadius,
|
||||
Widget? errorWidget,
|
||||
bool isWidth = false,
|
||||
}) {
|
||||
// bool isSvg = path.toLowerCase().endsWith('.svg');
|
||||
// if (isSvg) {
|
||||
@@ -180,6 +186,11 @@ class HelpImg {
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
return FadeInImage.assetNetwork(
|
||||
placeholder: isWidth==true ? ConstImg.spaceImgW : ConstImg.spaceImgH, image: path,
|
||||
width: width, height: height, fit: BoxFit.cover
|
||||
);
|
||||
|
||||
return Image.network(
|
||||
path,
|
||||
width: width,
|
||||
@@ -187,33 +198,17 @@ class HelpImg {
|
||||
fit: fit,
|
||||
loadingBuilder: (context, child, loadingProgress) {
|
||||
if (loadingProgress == null) return child;
|
||||
return SizedBox(
|
||||
width: width, height: height,
|
||||
child: Center(
|
||||
//CircularProgressIndicator
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
return HelpImg.asset(isWidth==true ? ConstImg.spaceImgW : ConstImg.spaceImgH, fit: BoxFit.fill,
|
||||
width: width, height: height
|
||||
);
|
||||
},
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
// ✅ 关键:处理加载失败的情况
|
||||
return errorWidget ??
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
color: Colors.grey[300],
|
||||
child: const Icon(
|
||||
Icons.broken_image,
|
||||
color: Colors.grey,
|
||||
size: 40,
|
||||
SizedBox(
|
||||
width: width, height: height,
|
||||
child: HelpImg.asset(isWidth==true ? ConstImg.spaceImgW : ConstImg.spaceImgH, fit: BoxFit.fill,
|
||||
width: width, height: height
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user