Last active
December 22, 2021 11:35
-
-
Save Roaa94/d0b07c674c7c3a14fb6047c039cffb38 to your computer and use it in GitHub Desktop.
Cached Network Image Wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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