可自定义加载时占位图片和加载失败时展示的图片
class ImageBuildView extends StatelessWidget {
String? url;
double radius;
double? width;
double? height;
String placeholder;
ImageBuildView(
{super.key,
this.url,
this.width,
this.height,
this.radius = 50,
this.placeholder = "assets/images/loading.png"});
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(radius),
child: FadeInImage.assetNetwork(
placeholder: placeholder,
image: url != null && url!.isNotEmpty ? "${Api.BASE_URL}/$url" : '',
fit: BoxFit.cover,
width: width ?? 60.w,
height: height ?? 60.w,
imageErrorBuilder: (context, error, stackTrace) {
return Center(
child: Image.asset("assets/images/image_error.png",
width: (width ?? 60.w) - 20.w, height: (height ?? 60.w) - 20.w),
);
},
),
);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35