From 595b8ad352f294ab06f298538369b32046d76bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Sun, 13 Oct 2024 21:58:11 +0400 Subject: [PATCH] lab_4_done --- lib/presentation/pages/home_page.dart | 98 ++++++++++++++------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/lib/presentation/pages/home_page.dart b/lib/presentation/pages/home_page.dart index 5078e59..f14abf2 100644 --- a/lib/presentation/pages/home_page.dart +++ b/lib/presentation/pages/home_page.dart @@ -34,17 +34,17 @@ class _HomePageState extends State { case ItemCategory.food: itemName = 'Food${random.nextInt(100)}'; imageUrl = - 'static/imgDatasets/food_for_cart/Image_${random.nextInt(5)}.jpg'; + 'static/imgDatasets/food_for_cart/Image_${random.nextInt(5)}.jpg'; break; case ItemCategory.clothing: itemName = 'Clothing${random.nextInt(100)}'; imageUrl = - 'static/imgDatasets/clothing_for_cart/clothing_${random.nextInt(5)}.jpg'; + 'static/imgDatasets/clothing_for_cart/clothing_${random.nextInt(5)}.jpg'; break; case ItemCategory.electronic: itemName = 'Electronic${random.nextInt(100)}'; imageUrl = - 'static/imgDatasets/electronic_for_cart/electronic_${random.nextInt(5)}.jpg'; + 'static/imgDatasets/electronic_for_cart/electronic_${random.nextInt(5)}.jpg'; break; } @@ -83,57 +83,61 @@ class _HomePageState extends State { itemCount: cart.items.length, itemBuilder: (context, index) { return Card( - margin: - const EdgeInsets.symmetric(vertical: 8, horizontal: 10), + margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 10), elevation: 4, - child: ListTile( - contentPadding: const EdgeInsets.all(16.0), - leading: ClipRRect( - borderRadius: BorderRadius.circular(10.0), - child: Image.asset( - cart.items[index].imgUrl, - width: 80, - height: 80, - fit: BoxFit.cover, + child: SizedBox( + + child: ListTile( + contentPadding: EdgeInsets.zero, + leading: ClipRRect( + borderRadius: BorderRadius.circular(10.0), + child: SizedBox( + width: 80, + height: 120, + child: Image.asset( + cart.items[index].imgUrl, + fit: BoxFit.cover, + ), + ), ), - ), - title: Text( - cart.items[index].name, - style: const TextStyle(fontSize: 18), - ), - subtitle: Text( - cart.items[index].category.toString().split('.').last, - style: const TextStyle(color: Colors.grey), - ), - trailing: IconButton( - icon: Icon( - likedItems[index] - ? Icons.thumb_up - : Icons.thumb_up_off_alt, - color: likedItems[index] ? Colors.red : Colors.grey, + title: Text( + cart.items[index].name, + style: const TextStyle(fontSize: 18), ), - onPressed: () { - setState(() { - likedItems[index] = !likedItems[index]; - }); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(likedItems[index] - ? 'Товар лайкнут!' - : 'Лайк убран!'), + subtitle: Text( + cart.items[index].category.toString().split('.').last, + style: const TextStyle(color: Colors.grey), + ), + trailing: IconButton( + icon: Icon( + likedItems[index] + ? Icons.thumb_up + : Icons.thumb_up_off_alt, + color: likedItems[index] ? Colors.red : Colors.grey, + ), + onPressed: () { + setState(() { + likedItems[index] = !likedItems[index]; + }); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(likedItems[index] + ? 'Товар лайкнут!' + : 'Лайк убран!'), + ), + ); + }, + ), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + DetailsPage(item: cart.items[index]), ), ); }, ), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - DetailsPage(item: cart.items[index]), - ), - ); - }, ), ); },