asset static method
Widget
asset(
- String assetPath, {
- Color? color,
- double? width,
- double? height,
- BoxFit fit = BoxFit.contain,
- AlignmentGeometry alignment = Alignment.center,
- PlaceholderBuilder? placeholderBuilder,
- String? package,
加载本地资源图片
Implementation
static Widget asset(
String assetPath, {
Color? color,
double? width,
double? height,
BoxFit fit = BoxFit.contain,
AlignmentGeometry alignment = Alignment.center,
PlaceholderBuilder? placeholderBuilder,
String? package,
}) {
ImageType type = ImageType.fromPath(assetPath);
if (type.isSvg) {
return SvgPicture.asset(
assetPath,
colorFilter: color == null
? null
: ColorFilter.mode(color, BlendMode.srcIn),
width: width,
height: height,
fit: fit,
alignment: alignment,
package: package,
placeholderBuilder: (context) =>
placeholderBuilder?.call(context) ??
_defaultPlaceholder(width, height),
);
} else {
return Image.asset(
assetPath,
color: color,
width: width,
height: height,
fit: fit,
alignment: alignment,
package: package,
errorBuilder: (context, _, _) =>
placeholderBuilder?.call(context) ??
_defaultPlaceholder(width, height),
);
}
}