@@ -16,7 +16,7 @@ import 'package:gogrocy/ui/shared/constants.dart' as constants;
16
16
typedef void CheckoutButtonPressed ();
17
17
18
18
class Cart extends StatelessWidget {
19
- ScrollController scrollController= new ScrollController ();
19
+ ScrollController scrollController = new ScrollController ();
20
20
21
21
@override
22
22
Widget build (BuildContext context) {
@@ -29,44 +29,94 @@ class Cart extends StatelessWidget {
29
29
if (model.state == ViewState .Busy )
30
30
return Center (child: CircularProgressIndicator ());
31
31
else if (model.state == ViewState .Intermediate ) {
32
- return ListView (
33
- shrinkWrap: true ,
34
- controller: scrollController,
35
- children: < Widget > [
36
- CartHeader (model: model.cartList,checkoutButtonPressed: (){scrollController.animateTo (scrollController.position.maxScrollExtent, duration: Duration (milliseconds: 500 ), curve: Curves .easeIn);print ("Callback succeeds" );},),
37
- CartList (model, model.intermediateCartList),
38
- CartBill (model.cartList,),
39
- CartFooter (model),
40
- SizedBox (height: 50 ,),
41
-
42
-
43
- ],
44
- );
45
- } else
46
- return ListView (
47
- shrinkWrap: true ,
48
- controller: scrollController,
49
- children: < Widget > [
50
- CartHeader (model: model.cartList,checkoutButtonPressed: (){scrollController.animateTo (scrollController.position.maxScrollExtent, duration: Duration (milliseconds: 500 ), curve: Curves .easeIn);print ("Callback succeeds" );}),
51
- CartList (model, model.cartList),
52
- CartBill (model.cartList),
53
- CartFooter (model),
54
- SizedBox (height: 50 ,),
32
+ if (model.cartList.sum == 0 ) {
33
+ return ListView (
34
+ shrinkWrap: true ,
35
+ controller: scrollController,
36
+ children: < Widget > [
37
+ CartHeader (
38
+ model: model.cartList,
39
+ checkoutButtonPressed: () {
40
+ scrollController.animateTo (
41
+ scrollController.position.maxScrollExtent,
42
+ duration: Duration (milliseconds: 500 ),
43
+ curve: Curves .easeIn);
44
+ print ("Callback succeeds" );
45
+ },
46
+ ),
47
+ CartList (model, model.intermediateCartList),
48
+ CartBill (
49
+ model.cartList,
50
+ ),
51
+ CartFooter (model),
52
+ SizedBox (
53
+ height: 50 ,
54
+ ),
55
+ ],
56
+ );
57
+ } else return emptyCart ();
55
58
56
- ],
57
- );
59
+ } else {
60
+ if (model.cartList.sum == 0 ) {
61
+ return emptyCart ();
62
+ } else
63
+ return ListView (
64
+ shrinkWrap: true ,
65
+ controller: scrollController,
66
+ children: < Widget > [
67
+ CartHeader (
68
+ model: model.cartList,
69
+ checkoutButtonPressed: () {
70
+ scrollController.animateTo (
71
+ scrollController.position.maxScrollExtent,
72
+ duration: Duration (milliseconds: 500 ),
73
+ curve: Curves .easeIn);
74
+ print ("Callback succeeds" );
75
+ }),
76
+ CartList (model, model.cartList),
77
+ CartBill (model.cartList),
78
+ CartFooter (model),
79
+ SizedBox (
80
+ height: 50 ,
81
+ ),
82
+ ],
83
+ );
84
+ }
58
85
},
59
86
),
60
87
);
61
88
}
89
+
90
+ Widget emptyCart () {
91
+ return Center (
92
+ child: Column (
93
+ mainAxisSize: MainAxisSize .max,
94
+ mainAxisAlignment: MainAxisAlignment .center,
95
+ children: < Widget > [
96
+ SizedBox (
97
+ width: 60.0 ,
98
+ height: 60.0 ,
99
+ child: Image (
100
+ image: AssetImage ("assets/images/empty-cart.png" ),
101
+ )),
102
+ Text (
103
+ "Your cart is Empty!" ,
104
+ style: TextStyle (
105
+ fontSize: 24.0 ,
106
+ fontFamily: 'Gilroy' ,
107
+ fontWeight: FontWeight .w500),
108
+ )
109
+ ],
110
+ ),
111
+ );
112
+ }
62
113
}
63
114
64
115
class CartHeader extends StatelessWidget {
65
-
66
116
cart_list model;
67
117
CheckoutButtonPressed checkoutButtonPressed;
68
118
69
- CartHeader ({this .model,this .checkoutButtonPressed});
119
+ CartHeader ({this .model, this .checkoutButtonPressed});
70
120
71
121
@override
72
122
Widget build (BuildContext context) {
@@ -92,11 +142,22 @@ class CartHeader extends StatelessWidget {
92
142
crossAxisAlignment: CrossAxisAlignment .start,
93
143
mainAxisSize: MainAxisSize .min,
94
144
children: < Widget > [
95
- Text ("Your Cart" ,
96
- style: TextStyle (fontFamily: 'Gilroy' ,fontSize: 32.0 ,fontWeight: FontWeight .bold, color: colors.CART_HEADER_COLOR ),),
97
- Text ("Grand Total Rs" + model.sum.toString (),
98
- style: TextStyle (fontFamily: 'Gilroy' ,fontSize: 14.0 ,fontWeight: FontWeight .w600, color: colors.CART_HEADER_COLOR ),),
99
-
145
+ Text (
146
+ "Your Cart" ,
147
+ style: TextStyle (
148
+ fontFamily: 'Gilroy' ,
149
+ fontSize: 32.0 ,
150
+ fontWeight: FontWeight .bold,
151
+ color: colors.CART_HEADER_COLOR ),
152
+ ),
153
+ Text (
154
+ "Grand Total Rs" + model.sum.toString (),
155
+ style: TextStyle (
156
+ fontFamily: 'Gilroy' ,
157
+ fontSize: 14.0 ,
158
+ fontWeight: FontWeight .w600,
159
+ color: colors.CART_HEADER_COLOR ),
160
+ ),
100
161
],
101
162
),
102
163
)
@@ -105,7 +166,7 @@ class CartHeader extends StatelessWidget {
105
166
),
106
167
),
107
168
Padding (
108
- padding: const EdgeInsets .only (left: 28.0 ,top: 12 ),
169
+ padding: const EdgeInsets .only (left: 28.0 , top: 12 ),
109
170
child: RawMaterialButton (
110
171
elevation: 0.0 ,
111
172
focusElevation: 1 ,
@@ -138,4 +199,3 @@ class CartHeader extends StatelessWidget {
138
199
);
139
200
}
140
201
}
141
-
0 commit comments