-
Notifications
You must be signed in to change notification settings - Fork 9
/
cart.dart
128 lines (124 loc) · 5.07 KB
/
cart.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import 'package:ECommerceApp/consts/colors.dart';
import 'package:ECommerceApp/consts/my_icons.dart';
import 'package:ECommerceApp/provider/cart_provider.dart';
import 'package:ECommerceApp/services/global_method.dart';
import 'package:ECommerceApp/widget/cart_empty.dart';
import 'package:ECommerceApp/widget/cart_full.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class CartScreen extends StatelessWidget {
static const routeName = '/CartScreen';
@override
Widget build(BuildContext context) {
GlobalMethods globalMethods =GlobalMethods();
final cartProvider = Provider.of<CartProvider>(context);
return cartProvider.getCartItems.isEmpty
? Scaffold(body: CartEmpty())
: Scaffold(
bottomSheet: checkoutSection(context, cartProvider.totalAmount),
appBar: AppBar(
backgroundColor: Theme.of(context).backgroundColor,
title: Text('Cart (${cartProvider.getCartItems.length})'),
actions: [
IconButton(
onPressed: () {
globalMethods.showDialogg(
'Clear cart!',
'Your cart will be cleared!',
() => cartProvider
.clearCart(),context);
// cartProvider.clearCart();
},
icon: Icon(MyAppIcons.trash),
)
],
),
body: Container(
margin: EdgeInsets.only(bottom: 60),
child: ListView.builder(
itemCount: cartProvider.getCartItems.length,
itemBuilder: (BuildContext ctx, int index) {
return ChangeNotifierProvider.value(
value: cartProvider.getCartItems.values.toList()[index],
child: CartFull(
productId:
cartProvider.getCartItems.keys.toList()[index],
// id: cartProvider.getCartItems.values.toList()[index].id,
// productId: cartProvider.getCartItems.keys.toList()[index],
// price: cartProvider.getCartItems.values.toList()[index].price,
// title: cartProvider.getCartItems.values.toList()[index].title,
// imageUrl: cartProvider.getCartItems.values.toList()[index].imageUrl,
// quatity: cartProvider.getCartItems.values.toList()[index].quantity,
),
);
}),
),
);
}
Widget checkoutSection(BuildContext ctx, double subtotal) {
return Container(
decoration: BoxDecoration(
border: Border(
top: BorderSide(color: Colors.grey, width: 0.5),
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
/// mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 2,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
gradient: LinearGradient(colors: [
ColorsConsts.gradiendLStart,
ColorsConsts.gradiendLEnd,
], stops: [
0.0,
0.7
]),
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(30),
onTap: () {},
splashColor: Theme.of(ctx).splashColor,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Checkout',
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(ctx).textSelectionColor,
fontSize: 18,
fontWeight: FontWeight.w600),
),
),
),
),
),
),
Spacer(),
Text(
'Total:',
style: TextStyle(
color: Theme.of(ctx).textSelectionColor,
fontSize: 18,
fontWeight: FontWeight.w600),
),
Text(
'US ${subtotal.toStringAsFixed(3)}',
//textAlign: TextAlign.center,
style: TextStyle(
color: Colors.blue,
fontSize: 18,
fontWeight: FontWeight.w500),
),
],
),
));
}
}