renderAsset method

Widget renderAsset(
  1. dynamic asset, {
  2. double? width,
  3. double? height,
})

Implementation

Widget renderAsset(dynamic asset, {double? width, double? height}) {
  AssetType type = assetType(asset);
  if (type == AssetType.lottie) {
    return Lottie.asset(
      asset,
      height: height,
      width: width,
      fit: fit,
      errorBuilder: errorBuilder,
    );
  } else if (type == AssetType.svg) {
    return SvgPicture.asset(
      asset,
      height: height,
      width: width,
      fit: fit,
      colorFilter:
          color != null ? ColorFilter.mode(color!, BlendMode.srcIn) : null,
      placeholderBuilder: (context) {
        return placeholder ?? const SizedBox.shrink();
      },
    );
  } else if (type == AssetType.imageAsset) {
    return Image.asset(
      asset,
      fit: fit,
      height: height,
      width: width,
      color: color,
      errorBuilder: errorBuilder,
    );
  } else if (type == AssetType.imageFile) {
    return Image.file(
      File(asset),
      fit: fit,
      height: height,
      width: width,
      color: color,
      errorBuilder: errorBuilder,
    );
  } else if (type == AssetType.icon) {
    return Icon(asset, size: height, color: color);
  } else if (type == AssetType.network) {
    return CachedNetworkImage(
      fit: fit,
      imageUrl: asset,
      placeholder: (context, url) => placeholder ?? const SizedBox.shrink(),
      errorWidget: (context, url, error) =>
          errorWidget ?? const SizedBox.shrink(),
      height: height,
      width: width,
    );
  } else {
    return const SizedBox.shrink();
  }
}