Skip to content

Instantly share code, notes, and snippets.

@Roaa94
Last active December 22, 2021 11:35
Show Gist options
  • Save Roaa94/d0b07c674c7c3a14fb6047c039cffb38 to your computer and use it in GitHub Desktop.
Save Roaa94/d0b07c674c7c3a14fb6047c039cffb38 to your computer and use it in GitHub Desktop.
Cached Network Image Wrapper
import 'package:cached_network_image/cached_network_image.dart';
class CachedNetworkImageWrapper extends StatelessWidget {
final String imageUrl;
final Widget? loader;
final Widget? errorWidget;
final double? height;
final double? width;
final BoxFit fit;
final Alignment alignment;
final Color? color;
final BlendMode? colorBlendMode;
const CachedNetworkImageWrapper({
required this.imageUrl,
this.loader,
this.errorWidget,
this.height,
this.width,
this.fit = BoxFit.cover,
this.alignment = Alignment.center,
this.color,
this.colorBlendMode,
});
@override
Widget build(BuildContext context) {
return CachedNetworkImage(
placeholder: (BuildContext context, String url) => loader ?? const CircularProgressIndicator(),
imageUrl: imageUrl,
width: width,
height: height,
fit: fit,
color: color,
colorBlendMode: colorBlendMode,
alignment: alignment,
errorWidget: (BuildContext context, String url, dynamic error) {
return errorWidget ?? Image.asset('assets/my-error-image.jpg');
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment