1import 'package:cached_network_image/cached_network_image.dart';
2import 'package:flutter/material.dart';
3import 'package:grain/app_icons.dart';
4
5class AppImage extends StatelessWidget {
6 final String? url;
7 final double? width;
8 final double? height;
9 final BoxFit fit;
10 final BorderRadius? borderRadius;
11 final Widget? placeholder;
12 final Widget? errorWidget;
13
14 const AppImage({
15 super.key,
16 required this.url,
17 this.width,
18 this.height,
19 this.fit = BoxFit.cover,
20 this.borderRadius,
21 this.placeholder,
22 this.errorWidget,
23 });
24
25 @override
26 Widget build(BuildContext context) {
27 final theme = Theme.of(context);
28 if (url == null || url!.isEmpty) {
29 return errorWidget ??
30 Container(
31 width: width,
32 height: height,
33 color: theme.colorScheme.surface,
34 child: Icon(AppIcons.brokenImage, color: Colors.grey),
35 );
36 }
37 final image = CachedNetworkImage(
38 imageUrl: url!,
39 width: width,
40 height: height,
41 fit: fit,
42 fadeInDuration: Duration.zero,
43 fadeOutDuration: Duration.zero,
44 placeholder: (context, _) =>
45 placeholder ??
46 Container(
47 width: width,
48 height: height,
49 color: theme.colorScheme.surface,
50 // child: const Center(
51 // child: CircularProgressIndicator(
52 // strokeWidth: 2,
53 // color: Color(0xFF0EA5E9),
54 // ),
55 // ),
56 ),
57 errorWidget: (context, _, __) =>
58 errorWidget ??
59 Container(
60 width: width,
61 height: height,
62 color: theme.colorScheme.surface,
63 child: Icon(AppIcons.brokenImage, color: Colors.grey),
64 ),
65 );
66 if (borderRadius != null) {
67 return ClipRRect(
68 borderRadius: borderRadius!, // BorderRadius is a subclass of BorderRadiusGeometry
69 child: image,
70 );
71 }
72 return image;
73 }
74}