-
Notifications
You must be signed in to change notification settings - Fork 1
/
p1_my_cart_page.dart
61 lines (58 loc) · 1.79 KB
/
p1_my_cart_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import 'package:app/common/data/item.dart';
import 'package:app/common/utility/show_purchased_snackbar.dart';
import 'package:app/common/widget/cart_item_tile.dart';
import 'package:app/common/widget/cart_total_amount.dart';
import 'package:app/common/widget/empty_state.dart';
import 'package:flutter/material.dart';
class P1MyCartPage extends StatelessWidget {
const P1MyCartPage({
super.key,
required this.myCartItems,
required this.onRemoveItem,
required this.onClearItems,
});
final List<Item> myCartItems;
final void Function(Item) onRemoveItem;
final VoidCallback onClearItems;
@override
Widget build(BuildContext context) {
final totalAmount =
myCartItems.fold<int>(0, (sum, item) => sum + item.price);
return Scaffold(
appBar: AppBar(
title: const Text('My Cart (P1)'),
),
body: Column(
children: [
Expanded(
child: myCartItems.isNotEmpty
? ListView.builder(
itemCount: myCartItems.length,
itemBuilder: (context, index) {
final item = myCartItems[index];
return CartItemTile(
item: item,
onTapRemove: () => onRemoveItem(item),
);
},
)
: const EmptyState(),
),
const Divider(),
CartTotalAmount(
totalAmount: totalAmount,
onTapBuy: () {
showPurchasedSnackbar(
context,
itemCount: myCartItems.length,
totalAmount: totalAmount,
);
onClearItems();
Navigator.of(context).pop();
},
),
],
),
);
}
}