Changed method for displaying images

This commit is contained in:
Mykyta Dubovyi 2023-12-19 01:22:45 +02:00
parent a99e181412
commit d1e8f3c4f2

View File

@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:graphql/client.dart'; import 'package:graphql/client.dart';
@ -177,22 +178,10 @@ class CartItem extends StatelessWidget{
Container( Container(
width: 100, width: 100,
alignment: Alignment.center, alignment: Alignment.center,
child: Image.network( child: CachedNetworkImage(
_product.imageUrls[0], imageUrl: _product.imageUrls[0],
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) { placeholder: (context, url) => CircularProgressIndicator(),
if (loadingProgress == null) return child; errorWidget: (context, url, error) => Image.asset('../assets/img/default-white.png'),
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
: null,
),
);
},
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
// Повертає зображення за замовчуванням у випадку помилки
return Image.asset('../assets/img/default-white.png');
},
), ),
), ),
SizedBox(width: 20), SizedBox(width: 20),