image static method
传入图片名字获取图片Widget,注意不需要带路径
Implementation
static Widget image(String? imageName,
{double? width,
double? height,
double? size,
BoxFit fit = BoxFit.contain,
bool excludeFromSemantics = false,
bool gaplessPlayback = false,
Color? imageColor,
bool primary = false,
BuildContext? context}) {
if (imageName == null || imageName.isEmpty) {
return SizedBox(width: width, height: height,);
}
try {
var image = Image.asset(imagePath(imageName), width: width ?? size,
height: height ?? size, fit: fit, excludeFromSemantics: excludeFromSemantics,
gaplessPlayback: gaplessPlayback, errorBuilder: (context, object, trace) {
return SizedBox(width: width, height: height,);
},
);
return imageColor != null || (primary && context != null)
? ColorFiltered(colorFilter: ColorFilter.mode(
primary ? Theme.of(context!).colorScheme.primary : imageColor!, BlendMode.srcIn), child: image,
) : image;
} catch (e) {
return SizedBox(width: width, height: height,);
}
}