2024-03-18 13:23:58 +08:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2024-03-22 17:26:57 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2024-03-18 13:23:58 +08:00
|
|
|
import 'package:sk_base_mobile/app_theme.dart';
|
2024-03-22 17:26:57 +08:00
|
|
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
2024-03-18 13:23:58 +08:00
|
|
|
|
|
|
|
class FadeInCacheImage extends StatefulWidget {
|
|
|
|
final double? width;
|
|
|
|
final double? height;
|
|
|
|
final String? url;
|
|
|
|
final BoxFit? fit;
|
2024-03-31 17:13:29 +08:00
|
|
|
final bool compress;
|
|
|
|
final bool canFullscreen;
|
2024-04-10 17:08:26 +08:00
|
|
|
final Widget? defaultWidget;
|
2024-03-31 17:13:29 +08:00
|
|
|
const FadeInCacheImage(
|
|
|
|
{super.key,
|
2024-03-18 13:23:58 +08:00
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
this.url,
|
2024-04-10 17:08:26 +08:00
|
|
|
this.defaultWidget,
|
2024-03-18 13:23:58 +08:00
|
|
|
this.fit = BoxFit.cover,
|
|
|
|
this.compress = false,
|
2024-03-31 17:13:29 +08:00
|
|
|
this.canFullscreen = false});
|
2024-03-18 13:23:58 +08:00
|
|
|
|
|
|
|
@override
|
2024-03-31 17:13:29 +08:00
|
|
|
// ignore: library_private_types_in_public_api
|
2024-03-18 13:23:58 +08:00
|
|
|
_FadeInCacheImageState createState() => _FadeInCacheImageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FadeInCacheImageState extends State<FadeInCacheImage> {
|
|
|
|
late BuildContext theContext;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
theContext = context;
|
|
|
|
|
|
|
|
if ((widget.url == null || widget.url == '' || widget.url == 'null')) {
|
2024-03-28 15:13:27 +08:00
|
|
|
return defaultImg();
|
2024-03-18 13:23:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return buildImg(widget.url);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Future getImg() {
|
|
|
|
// return MediaUtil().generateLogoUrl(widget.url);
|
|
|
|
// }
|
|
|
|
|
|
|
|
Widget buildImg(String? url) {
|
|
|
|
return CachedNetworkImage(
|
|
|
|
imageUrl: url ?? '',
|
|
|
|
width: widget.width,
|
|
|
|
height: widget.height,
|
2024-04-09 08:31:17 +08:00
|
|
|
imageBuilder: (context, imageProvider) => Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
image: DecorationImage(
|
|
|
|
image: imageProvider,
|
|
|
|
fit: widget.fit ?? BoxFit.cover,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-03-18 13:23:58 +08:00
|
|
|
placeholder: (context, url) => Container(
|
2024-03-26 11:35:39 +08:00
|
|
|
decoration: const BoxDecoration(color: AppTheme.grey),
|
|
|
|
child: const CupertinoActivityIndicator(),
|
|
|
|
),
|
2024-03-28 15:13:27 +08:00
|
|
|
errorWidget: (context, error, stackTrace) => defaultImg(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget defaultImg() {
|
|
|
|
return Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
width: widget.width,
|
|
|
|
height: widget.height,
|
2024-04-10 17:08:26 +08:00
|
|
|
child: widget.defaultWidget ??
|
|
|
|
Icon(Icons.image_not_supported,
|
|
|
|
size: ScreenAdaper.height((widget.width ?? 200)),
|
|
|
|
color: AppTheme.grey),
|
2024-03-18 13:23:58 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|