import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:sk_base_mobile/app_theme.dart'; import 'package:sk_base_mobile/util/screen_adaper_util.dart'; class FadeInCacheImage extends StatefulWidget { final double? width; final double? height; final String? url; final BoxFit? fit; final bool compress; final bool canFullscreen; const FadeInCacheImage( {super.key, this.width, this.height, this.url, this.fit = BoxFit.cover, this.compress = false, this.canFullscreen = false}); @override // ignore: library_private_types_in_public_api _FadeInCacheImageState createState() => _FadeInCacheImageState(); } class _FadeInCacheImageState extends State { 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')) { return defaultImg(); } 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, imageBuilder: (context, imageProvider) => Container( decoration: BoxDecoration( image: DecorationImage( image: imageProvider, fit: widget.fit ?? BoxFit.cover, ), ), ), placeholder: (context, url) => Container( decoration: const BoxDecoration(color: AppTheme.grey), child: const CupertinoActivityIndicator(), ), errorWidget: (context, error, stackTrace) => defaultImg(), ); } Widget defaultImg() { return Container( alignment: Alignment.center, width: widget.width, height: widget.height, child: Icon(Icons.image_not_supported, size: ScreenAdaper.height((widget.width ?? 200)), color: AppTheme.grey), ); } }