lab_4_done

This commit is contained in:
Алексей Крюков 2024-10-13 21:58:11 +04:00
parent ba1d0908e0
commit 595b8ad352

View File

@ -34,17 +34,17 @@ class _HomePageState extends State<HomePage> {
case ItemCategory.food: case ItemCategory.food:
itemName = 'Food${random.nextInt(100)}'; itemName = 'Food${random.nextInt(100)}';
imageUrl = imageUrl =
'static/imgDatasets/food_for_cart/Image_${random.nextInt(5)}.jpg'; 'static/imgDatasets/food_for_cart/Image_${random.nextInt(5)}.jpg';
break; break;
case ItemCategory.clothing: case ItemCategory.clothing:
itemName = 'Clothing${random.nextInt(100)}'; itemName = 'Clothing${random.nextInt(100)}';
imageUrl = imageUrl =
'static/imgDatasets/clothing_for_cart/clothing_${random.nextInt(5)}.jpg'; 'static/imgDatasets/clothing_for_cart/clothing_${random.nextInt(5)}.jpg';
break; break;
case ItemCategory.electronic: case ItemCategory.electronic:
itemName = 'Electronic${random.nextInt(100)}'; itemName = 'Electronic${random.nextInt(100)}';
imageUrl = imageUrl =
'static/imgDatasets/electronic_for_cart/electronic_${random.nextInt(5)}.jpg'; 'static/imgDatasets/electronic_for_cart/electronic_${random.nextInt(5)}.jpg';
break; break;
} }
@ -83,57 +83,61 @@ class _HomePageState extends State<HomePage> {
itemCount: cart.items.length, itemCount: cart.items.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return Card( return Card(
margin: margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
elevation: 4, elevation: 4,
child: ListTile( child: SizedBox(
contentPadding: const EdgeInsets.all(16.0),
leading: ClipRRect( child: ListTile(
borderRadius: BorderRadius.circular(10.0), contentPadding: EdgeInsets.zero,
child: Image.asset( leading: ClipRRect(
cart.items[index].imgUrl, borderRadius: BorderRadius.circular(10.0),
width: 80, child: SizedBox(
height: 80, width: 80,
fit: BoxFit.cover, height: 120,
child: Image.asset(
cart.items[index].imgUrl,
fit: BoxFit.cover,
),
),
), ),
), title: Text(
title: Text( cart.items[index].name,
cart.items[index].name, style: const TextStyle(fontSize: 18),
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,
), ),
onPressed: () { subtitle: Text(
setState(() { cart.items[index].category.toString().split('.').last,
likedItems[index] = !likedItems[index]; style: const TextStyle(color: Colors.grey),
}); ),
ScaffoldMessenger.of(context).showSnackBar( trailing: IconButton(
SnackBar( icon: Icon(
content: Text(likedItems[index] 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]),
),
);
},
), ),
); );
}, },