YImage function
加载图像
Implementation
Widget YImage(
double? width,
double? height,
String url, {
BoxFit fit = BoxFit.contain,
String? imagePlaceHolder,
}) {
if (yIsNullOrEmpty(url)) return Image.asset(yIsNullOrEmpty(imagePlaceHolder) ? YConfig.imagePlaceHolder : imagePlaceHolder!, width: width, height: height, fit: fit);
return ExtendedImage.network(
url,
loadStateChanged: (ExtendedImageState state) {
switch (state.extendedImageLoadState) {
case LoadState.loading:
return Image.asset(yIsNullOrEmpty(imagePlaceHolder) ? YConfig.imagePlaceHolder : imagePlaceHolder!, width: width, height: height, fit: fit);
case LoadState.completed:
return state.completedWidget;
case LoadState.failed:
return yIsNullOrEmpty(imagePlaceHolder) ? SizedBox(width: width, height: height, child: const Icon(Icons.error)) : Image.asset(imagePlaceHolder!, width: width, height: height, fit: fit);
}
},
width: width,
height: height,
fit: fit,
);
}