Advertisement
rafisbr

Cart Page

Jul 13th, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:shamo/providers/cart_provider.dart';
  4. import 'package:shamo/widgets/cart_card.dart';
  5.  
  6. import '../theme.dart';
  7.  
  8. class CartPage extends StatelessWidget {
  9. const CartPage({Key? key}) : super(key: key);
  10.  
  11. @override
  12. Widget build(BuildContext context) {
  13. CartProvider cartProvider = Provider.of<CartProvider>(context);
  14. header() {
  15. return AppBar(
  16. backgroundColor: backgroundColor1,
  17. centerTitle: true,
  18. title: Text(
  19. 'Your Cart',
  20. ),
  21. elevation: 0,
  22. );
  23. }
  24.  
  25. Widget emptyCart() {
  26. return Center(
  27. child: Column(
  28. mainAxisAlignment: MainAxisAlignment.center,
  29. children: [
  30. Image.asset(
  31. 'assets/icon_empty_card.png',
  32. width: 80,
  33. ),
  34. SizedBox(
  35. height: 20,
  36. ),
  37. Text(
  38. 'Opss! Your Cart is Empty',
  39. style: primaryTextStyle.copyWith(
  40. fontSize: 16,
  41. fontWeight: medium,
  42. ),
  43. ),
  44. SizedBox(
  45. height: 12,
  46. ),
  47. Text(
  48. 'Let\'s find your favorite shoes',
  49. style: secondaryTextStyle,
  50. ),
  51. Container(
  52. width: 154,
  53. height: 44,
  54. margin: EdgeInsets.only(
  55. top: 20,
  56. ),
  57. child: TextButton(
  58. onPressed: () {
  59. Navigator.pushNamedAndRemoveUntil(
  60. context, '/main-page', (route) => false);
  61. },
  62. style: TextButton.styleFrom(
  63. backgroundColor: primaryColor,
  64. shape: RoundedRectangleBorder(
  65. borderRadius: BorderRadius.circular(12),
  66. ),
  67. ),
  68. child: Text(
  69. 'Explore Store',
  70. style: primaryTextStyle.copyWith(
  71. fontSize: 16,
  72. fontWeight: medium,
  73. ),
  74. ),
  75. ),
  76. ),
  77. ],
  78. ),
  79. );
  80. }
  81.  
  82. Widget content() {
  83. return ListView(
  84. padding: EdgeInsets.symmetric(
  85. horizontal: defaultMargin,
  86. ),
  87. children: cartProvider.carts
  88. .map(
  89. (cart) => CartCard(cart),
  90. )
  91. .toList(),
  92. );
  93. }
  94.  
  95. Widget customBottomNav() {
  96. return Container(
  97. height: 180,
  98. child: Column(
  99. children: [
  100. SizedBox(
  101. height: 20,
  102. ),
  103. Container(
  104. margin: EdgeInsets.symmetric(
  105. horizontal: defaultMargin,
  106. ),
  107. child: Row(
  108. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  109. children: [
  110. Text(
  111. 'Subtotal',
  112. style: primaryTextStyle,
  113. ),
  114. Text(
  115. '\$ ${cartProvider.totalPrice()}',
  116. style: priceTextStyle.copyWith(
  117. fontSize: 16,
  118. fontWeight: semibold,
  119. ),
  120. ),
  121. ],
  122. ),
  123. ),
  124. SizedBox(
  125. height: 20,
  126. ),
  127. Divider(
  128. thickness: 0.3,
  129. color: subtitleColor,
  130. ),
  131. SizedBox(
  132. height: 20,
  133. ),
  134. Container(
  135. height: 50,
  136. margin: EdgeInsets.symmetric(
  137. horizontal: defaultMargin,
  138. ),
  139. child: TextButton(
  140. onPressed: () {
  141. Navigator.pushNamed(context, '/checkout');
  142. },
  143. style: TextButton.styleFrom(
  144. backgroundColor: primaryColor,
  145. padding: EdgeInsets.symmetric(
  146. horizontal: 20,
  147. ),
  148. shape: RoundedRectangleBorder(
  149. borderRadius: BorderRadius.circular(12),
  150. ),
  151. ),
  152. child: Row(
  153. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  154. children: [
  155. Text(
  156. 'Continue to Checkout',
  157. style: primaryTextStyle.copyWith(
  158. fontSize: 16,
  159. fontWeight: semibold,
  160. ),
  161. ),
  162. Icon(
  163. Icons.arrow_forward,
  164. color: primaryTextColor,
  165. ),
  166. ],
  167. ),
  168. ),
  169. ),
  170. ],
  171. ),
  172. );
  173. }
  174.  
  175. return Scaffold(
  176. backgroundColor: backgroundColor3,
  177. appBar: header(),
  178. body: cartProvider.carts.length == 0 ? emptyCart() : content(),
  179. bottomNavigationBar:
  180. cartProvider.carts.length == 0 ? SizedBox() : customBottomNav(),
  181. );
  182. }
  183. }
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement