asset static method

Widget asset(
  1. String assetPath, {
  2. Color? color,
  3. double? width,
  4. double? height,
  5. BoxFit fit = BoxFit.contain,
  6. AlignmentGeometry alignment = Alignment.center,
  7. PlaceholderBuilder? placeholderBuilder,
  8. 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),
    );
  }
}