getAssetImg static method

Widget getAssetImg({
  1. required String imagePath,
  2. BoxFit boxFit = BoxFit.cover,
  3. double? height,
  4. double? width,
  5. Widget? errorWidget,
  6. Color? color,
  7. ImageFormat format = ImageFormat.png,
})

Implementation

static Widget getAssetImg({
  required String imagePath,
  BoxFit boxFit = BoxFit.cover,
  double? height,
  double? width,
  Widget? errorWidget,
  Color? color,
  ImageFormat format = ImageFormat.png,
}) {
  return Image.asset(
    'assets/images/$imagePath.${format.value}',
    fit: boxFit,
    height: height,
    width: width,
    color: color,
    cacheHeight: height?.toInt(),
    cacheWidth: width?.toInt(),
    errorBuilder: (BuildContext context, Object error, StackTrace? stackTrace) {
      return errorWidget ?? const Icon(Icons.broken_image);
    },
    frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
      if (wasSynchronouslyLoaded) return child;
      return AnimatedOpacity(
        opacity: frame == null ? 0 : 1,
        duration: const Duration(seconds: 1),
        curve: Curves.easeOut,
        child: child,
      );
    },
  );
}