getAssetImg static method
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,
);
},
);
}