-
Notifications
You must be signed in to change notification settings - Fork 1
/
p7_my_cart_page.dart
57 lines (55 loc) · 1.96 KB
/
p7_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
import 'package:app/common/data/my_cart_state.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:app/p7/p7_my_cart_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class P7MyCartPage extends StatelessWidget {
const P7MyCartPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My Cart (P7)'),
),
// ⭐️ Use BlocBuilder to listen to changes in the Cubit.
body: BlocBuilder<P7MyCartCubit, MyCartState>(
builder: (context, myCart) => Column(
children: [
Expanded(
child: myCart.items.isNotEmpty
? ListView.builder(
itemCount: myCart.items.length,
itemBuilder: (context, index) {
final item = myCart.items.elementAt(index);
return CartItemTile(
item: item,
// ⭐️ Update state with Cubit.
onTapRemove: () =>
context.read<P7MyCartCubit>().remove(item),
);
},
)
: const EmptyState(),
),
const Divider(),
CartTotalAmount(
totalAmount: myCart.totalAmount,
onTapBuy: () {
showPurchasedSnackbar(
context,
itemCount: myCart.items.length,
totalAmount: myCart.totalAmount,
);
context.read<P7MyCartCubit>().clear();
Navigator.of(context).pop();
},
),
],
),
),
);
}
}