Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- import 'package:shamo/providers/cart_provider.dart';
- import 'package:shamo/widgets/cart_card.dart';
- import '../theme.dart';
- class CartPage extends StatelessWidget {
- const CartPage({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- CartProvider cartProvider = Provider.of<CartProvider>(context);
- header() {
- return AppBar(
- backgroundColor: backgroundColor1,
- centerTitle: true,
- title: Text(
- 'Your Cart',
- ),
- elevation: 0,
- );
- }
- Widget emptyCart() {
- return Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Image.asset(
- 'assets/icon_empty_card.png',
- width: 80,
- ),
- SizedBox(
- height: 20,
- ),
- Text(
- 'Opss! Your Cart is Empty',
- style: primaryTextStyle.copyWith(
- fontSize: 16,
- fontWeight: medium,
- ),
- ),
- SizedBox(
- height: 12,
- ),
- Text(
- 'Let\'s find your favorite shoes',
- style: secondaryTextStyle,
- ),
- Container(
- width: 154,
- height: 44,
- margin: EdgeInsets.only(
- top: 20,
- ),
- child: TextButton(
- onPressed: () {
- Navigator.pushNamedAndRemoveUntil(
- context, '/main-page', (route) => false);
- },
- style: TextButton.styleFrom(
- backgroundColor: primaryColor,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- ),
- ),
- child: Text(
- 'Explore Store',
- style: primaryTextStyle.copyWith(
- fontSize: 16,
- fontWeight: medium,
- ),
- ),
- ),
- ),
- ],
- ),
- );
- }
- Widget content() {
- return ListView(
- padding: EdgeInsets.symmetric(
- horizontal: defaultMargin,
- ),
- children: cartProvider.carts
- .map(
- (cart) => CartCard(cart),
- )
- .toList(),
- );
- }
- Widget customBottomNav() {
- return Container(
- height: 180,
- child: Column(
- children: [
- SizedBox(
- height: 20,
- ),
- Container(
- margin: EdgeInsets.symmetric(
- horizontal: defaultMargin,
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- 'Subtotal',
- style: primaryTextStyle,
- ),
- Text(
- '\$ ${cartProvider.totalPrice()}',
- style: priceTextStyle.copyWith(
- fontSize: 16,
- fontWeight: semibold,
- ),
- ),
- ],
- ),
- ),
- SizedBox(
- height: 20,
- ),
- Divider(
- thickness: 0.3,
- color: subtitleColor,
- ),
- SizedBox(
- height: 20,
- ),
- Container(
- height: 50,
- margin: EdgeInsets.symmetric(
- horizontal: defaultMargin,
- ),
- child: TextButton(
- onPressed: () {
- Navigator.pushNamed(context, '/checkout');
- },
- style: TextButton.styleFrom(
- backgroundColor: primaryColor,
- padding: EdgeInsets.symmetric(
- horizontal: 20,
- ),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- ),
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- 'Continue to Checkout',
- style: primaryTextStyle.copyWith(
- fontSize: 16,
- fontWeight: semibold,
- ),
- ),
- Icon(
- Icons.arrow_forward,
- color: primaryTextColor,
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- );
- }
- return Scaffold(
- backgroundColor: backgroundColor3,
- appBar: header(),
- body: cartProvider.carts.length == 0 ? emptyCart() : content(),
- bottomNavigationBar:
- cartProvider.carts.length == 0 ? SizedBox() : customBottomNav(),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement