ar_tourism_flutter_unity/lib/components/cached_image.dart
2025-05-14 17:04:13 +08:00

60 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
class CachedImage extends StatelessWidget {
final String imageUrl;
final double? width;
final double? height;
final BoxFit? fit;
final BorderRadius? borderRadius;
final Widget Function(BuildContext, String, dynamic)? errorWidget;
final Widget Function(BuildContext, String)? placeholder;
const CachedImage({
Key? key,
required this.imageUrl,
this.width,
this.height,
this.fit,
this.borderRadius,
this.errorWidget,
this.placeholder,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Widget image = CachedNetworkImage(
imageUrl: imageUrl,
width: width,
height: height,
fit: fit ?? BoxFit.cover,
placeholder: placeholder ?? (context, url) => Container(
color: const Color(0xFF2C2C2C),
// child: const Center(
// child: CircularProgressIndicator(
// color: Color(0xff7DDFA4),
// ),
// ),
),
errorWidget: errorWidget ?? (context, url, error) => Container(
color: const Color(0xFF2C2C2C),
child: const Center(
child: Icon(
Icons.error,
color: Colors.white54,
),
),
),
);
if (borderRadius != null) {
return ClipRRect(
borderRadius: borderRadius!,
child: image,
);
}
return image;
}
}