2024-08-26 12:26:07 +00:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:rhythm_box/platform.dart';
|
|
|
|
|
|
|
|
class AutoCacheImage extends StatelessWidget {
|
|
|
|
final String url;
|
|
|
|
final double? width, height;
|
2024-09-06 10:10:12 +00:00
|
|
|
final BoxFit? fit;
|
2024-08-26 12:26:07 +00:00
|
|
|
|
2024-09-06 10:10:12 +00:00
|
|
|
const AutoCacheImage(this.url,
|
|
|
|
{super.key, this.width, this.height, this.fit});
|
2024-08-26 12:26:07 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (PlatformInfo.canCacheImage) {
|
|
|
|
return CachedNetworkImage(
|
|
|
|
imageUrl: url,
|
|
|
|
width: width,
|
|
|
|
height: height,
|
2024-09-06 10:10:12 +00:00
|
|
|
fit: fit,
|
2024-08-26 12:26:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return Image.network(
|
|
|
|
url,
|
|
|
|
width: width,
|
|
|
|
height: height,
|
2024-09-06 10:10:12 +00:00
|
|
|
fit: fit,
|
2024-08-26 12:26:07 +00:00
|
|
|
);
|
|
|
|
}
|
2024-08-27 08:37:31 +00:00
|
|
|
|
|
|
|
static ImageProvider provider(String url) {
|
|
|
|
if (PlatformInfo.canCacheImage) {
|
|
|
|
return CachedNetworkImageProvider(url);
|
|
|
|
}
|
|
|
|
return NetworkImage(url);
|
|
|
|
}
|
2024-08-26 12:26:07 +00:00
|
|
|
}
|