code cleaning
This commit is contained in:
parent
b90c8df053
commit
5b166b9d97
|
|
@ -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,74 +51,50 @@ 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(
|
if (kIsWeb) {
|
||||||
child: Builder(builder: (context) {
|
if (_isLoading) {
|
||||||
if (kIsWeb) {
|
return _aspectRatioGenerator(
|
||||||
if (_isLoading) {
|
child: ShimmerPlaceholder(
|
||||||
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(
|
|
||||||
borderRadius: widget.borderRadius,
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue