From 5b166b9d9750469cf9101206a786bb352a0ed7dd Mon Sep 17 00:00:00 2001 From: MohammadTaha Basiri Date: Sun, 30 Jan 2022 15:37:52 +0330 Subject: [PATCH] code cleaning --- lib/widgets/skeleton_image.dart | 113 +++++++++++--------------------- 1 file changed, 39 insertions(+), 74 deletions(-) diff --git a/lib/widgets/skeleton_image.dart b/lib/widgets/skeleton_image.dart index aecc541..ed1f93d 100644 --- a/lib/widgets/skeleton_image.dart +++ b/lib/widgets/skeleton_image.dart @@ -39,22 +39,11 @@ class _SkeletonImageState extends State { Future _getImage() async { final url = RequestHelper.baseUrl + widget.imageUrl; - - // final storage = StorageService.webStorage; - // String? imageCache = storage['image-cache']; - // final Map data = imageCache == null ? {} : jsonDecode(imageCache); - // if (data.containsKey(url)) { - // _bytes = Uint8List.fromList( - // List.from(data[url]), - // ); - // } else { _bytes = (await http.get( Uri.parse(url), headers: {'Authorization': 'Bearer ${RequestService.token}'}, )) .bodyBytes; - // addImageToStorage(); - // } if (mounted) { setState(() { _isLoading = false; @@ -62,74 +51,50 @@ class _SkeletonImageState extends State { } } - // void addImageToStorage() { - // final storage = StorageService.webStorage; - // String? imageCache = storage['image-cache']; - // final Map data = imageCache == null ? {} : Map.from(jsonDecode(imageCache)); - // data.addAll({RequestHelper.baseUrl + widget.imageUrl: _bytes}); - // StorageService.webStorage.addAll({'image-cache': jsonEncode(data)}); - // } - @override Widget build(BuildContext context) { - return _aspectRatioGenerator( - child: Builder(builder: (context) { - if (kIsWeb) { - if (_isLoading) { - return ShimmerPlaceholder( - borderRadius: widget.borderRadius, - width: widget.aspectRatio == null ? widget.width : null, - height: widget.aspectRatio == null ? widget.height : null, - ); - } - return ClipRRect( - borderRadius: widget.borderRadius, - child: Image.memory( - _bytes, - fit: BoxFit.cover, - width: widget.width, - height: widget.height, - ), - ); - // Builder( - // builder: (context) { - // if (_bytes == null || _bytes!.isEmpty) { - // return ShimmerPlaceholder( - // borderRadius: widget.borderRadius, - // ); - // } - // return ClipRRect( - // borderRadius: widget.borderRadius, - // child: Image.memory( - // _bytes!, - // width: widget.width, - // height: widget.height, - // fit: BoxFit.cover, - // ), - // ); - // }, - // ); - } - return CachedNetworkImage( - httpHeaders: {'Authorization': 'Bearer ${RequestService.token}'}, - width: widget.width, - height: widget.height, - imageUrl: RequestHelper.baseUrl + widget.imageUrl, - imageBuilder: (context, imageProvider) => Container( - decoration: BoxDecoration( - borderRadius: widget.borderRadius ?? DesignConfig.lowBorderRadius, - image: DecorationImage( - image: imageProvider, - fit: BoxFit.cover, - ), - ), - ), - progressIndicatorBuilder: (context, url, progress) => - ShimmerPlaceholder( + if (kIsWeb) { + if (_isLoading) { + return _aspectRatioGenerator( + child: ShimmerPlaceholder( borderRadius: widget.borderRadius, + width: widget.aspectRatio == null ? widget.width : null, + height: widget.aspectRatio == null ? widget.height : null, ), ); - }), + } + return _aspectRatioGenerator( + child: ClipRRect( + borderRadius: widget.borderRadius, + child: Image.memory( + _bytes, + fit: BoxFit.cover, + width: widget.width, + height: widget.height, + ), + ), + ); + } + return _aspectRatioGenerator( + child: CachedNetworkImage( + httpHeaders: {'Authorization': 'Bearer ${RequestService.token}'}, + width: widget.width, + height: widget.height, + imageUrl: RequestHelper.baseUrl + widget.imageUrl, + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + borderRadius: widget.borderRadius ?? DesignConfig.lowBorderRadius, + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, + ), + ), + ), + progressIndicatorBuilder: (context, url, progress) => + ShimmerPlaceholder( + borderRadius: widget.borderRadius, + ), + ), ); }