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;
|
|
|
|
bool compress;
|
|
|
|
bool canFullscreen;
|
|
|
|
FadeInCacheImage(
|
|
|
|
{Key? key,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
this.url,
|
|
|
|
this.fit = BoxFit.cover,
|
|
|
|
this.compress = false,
|
|
|
|
this.canFullscreen = false})
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_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-22 17:26:57 +08:00
|
|
|
return Container(
|
|
|
|
width: widget.width,
|
|
|
|
height: widget.height,
|
|
|
|
child: Icon(Icons.image_not_supported,
|
|
|
|
size: ScreenAdaper.sp(100), color: AppTheme.grey),
|
|
|
|
);
|
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(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
imageUrl: url ?? '',
|
|
|
|
width: widget.width,
|
|
|
|
height: widget.height,
|
|
|
|
fit: widget.fit,
|
|
|
|
placeholder: (context, url) => Container(
|
|
|
|
decoration: BoxDecoration(color: AppTheme.grey),
|
|
|
|
child: CupertinoActivityIndicator(),
|
|
|
|
),
|
|
|
|
errorWidget: (context, error, stackTrace) => Image(
|
|
|
|
image: AssetImage(
|
|
|
|
'assets/images/deer_detail_banner1.jpg',
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|