49 lines
1.2 KiB
Dart
49 lines
1.2 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:yumi/ui_kit/components/sc_rotating_dots_loading.dart';
|
|
|
|
class CustomCachedImage extends StatelessWidget {
|
|
final String imageUrl;
|
|
final double? width;
|
|
final double? height;
|
|
final BoxFit fit;
|
|
final double borderRadius;
|
|
final Widget? placeholder;
|
|
final Widget? errorWidget;
|
|
|
|
const CustomCachedImage({
|
|
super.key,
|
|
required this.imageUrl,
|
|
this.width,
|
|
this.height,
|
|
this.fit = BoxFit.cover,
|
|
this.borderRadius = 0,
|
|
this.placeholder,
|
|
this.errorWidget,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(borderRadius),
|
|
child: CachedNetworkImage(
|
|
imageUrl: imageUrl,
|
|
width: width,
|
|
height: height,
|
|
fit: fit,
|
|
placeholder: (context, url) => placeholder ?? _defaultPlaceholder(),
|
|
errorWidget:
|
|
(context, url, error) => errorWidget ?? _defaultErrorWidget(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _defaultPlaceholder() {
|
|
return const SCRotatingDotsLoading();
|
|
}
|
|
|
|
Widget _defaultErrorWidget() {
|
|
return Center(child: Image.asset("sc_images/general/sc_icon_loading.png"));
|
|
}
|
|
}
|