code cleaning

This commit is contained in:
MohammadTaha Basiri 2022-01-30 15:37:52 +03:30
parent b90c8df053
commit 5b166b9d97
1 changed files with 39 additions and 74 deletions

View File

@ -39,22 +39,11 @@ class _SkeletonImageState extends State<SkeletonImage> {
Future<void> _getImage() async { Future<void> _getImage() async {
final url = RequestHelper.baseUrl + widget.imageUrl; 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<int>.from(data[url]),
// );
// } else {
_bytes = (await http.get( _bytes = (await http.get(
Uri.parse(url), Uri.parse(url),
headers: {'Authorization': 'Bearer ${RequestService.token}'}, headers: {'Authorization': 'Bearer ${RequestService.token}'},
)) ))
.bodyBytes; .bodyBytes;
// addImageToStorage();
// }
if (mounted) { if (mounted) {
setState(() { setState(() {
_isLoading = false; _isLoading = false;
@ -62,27 +51,20 @@ class _SkeletonImageState extends State<SkeletonImage> {
} }
} }
// 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return _aspectRatioGenerator(
child: Builder(builder: (context) {
if (kIsWeb) { if (kIsWeb) {
if (_isLoading) { if (_isLoading) {
return ShimmerPlaceholder( return _aspectRatioGenerator(
child: ShimmerPlaceholder(
borderRadius: widget.borderRadius, borderRadius: widget.borderRadius,
width: widget.aspectRatio == null ? widget.width : null, width: widget.aspectRatio == null ? widget.width : null,
height: widget.aspectRatio == null ? widget.height : null, height: widget.aspectRatio == null ? widget.height : null,
),
); );
} }
return ClipRRect( return _aspectRatioGenerator(
child: ClipRRect(
borderRadius: widget.borderRadius, borderRadius: widget.borderRadius,
child: Image.memory( child: Image.memory(
_bytes, _bytes,
@ -90,27 +72,11 @@ class _SkeletonImageState extends State<SkeletonImage> {
width: widget.width, width: widget.width,
height: widget.height, 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( return _aspectRatioGenerator(
child: CachedNetworkImage(
httpHeaders: {'Authorization': 'Bearer ${RequestService.token}'}, httpHeaders: {'Authorization': 'Bearer ${RequestService.token}'},
width: widget.width, width: widget.width,
height: widget.height, height: widget.height,
@ -128,8 +94,7 @@ class _SkeletonImageState extends State<SkeletonImage> {
ShimmerPlaceholder( ShimmerPlaceholder(
borderRadius: widget.borderRadius, borderRadius: widget.borderRadius,
), ),
); ),
}),
); );
} }