Skip to content

Commit

Permalink
task: adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Atuoha committed Oct 11, 2022
1 parent 78139e7 commit 7a495ad
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 75 deletions.
Binary file removed cart.png
Binary file not shown.
1 change: 1 addition & 0 deletions lib/components/search_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SearchBox extends StatelessWidget {
color: primaryColor,
),
),
showBadge: cartData.cartItems.isNotEmpty ? true:false,
child: const Icon(
Icons.shopping_bag_outlined,
size: 30,
Expand Down
2 changes: 2 additions & 0 deletions lib/models/cart.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class CartItem {
final String id;
final dynamic docId;
final String prodId;
final String prodName;
final String prodImgUrl;
Expand All @@ -9,6 +10,7 @@ class CartItem {

CartItem({
required this.id,
required this.docId,
required this.prodId,
required this.prodName,
required this.prodPrice,
Expand Down
1 change: 1 addition & 0 deletions lib/providers/cart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CartData extends ChangeNotifier {
void addToCart(CartItem cart) {
CartItem item = CartItem(
id: DateTime.now().toString(),
docId: cart.docId,
prodId: cart.prodId,
prodName: cart.prodName,
prodPrice: cart.prodPrice,
Expand Down
129 changes: 73 additions & 56 deletions lib/utilities/build_cart.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import '../../../constants/colors.dart';
import '../views/main/product/details.dart';

Dismissible buildCart(
void Function(String prodId) removeFromCart,
item,
BuildContext context,
void Function(String id) increaseQuantity,
void Function(String id) reduceQuantity,
) {
void Function(String prodId) removeFromCart,
item,
BuildContext context,
void Function(String id) increaseQuantity,
void Function(String id) reduceQuantity,
) {
return Dismissible(
onDismissed: (direction) => removeFromCart(item.prodId),
direction: DismissDirection.endToStart,
Expand Down Expand Up @@ -69,61 +71,76 @@ Dismissible buildCart(
key: ValueKey(item.id),
child: Card(
elevation: 3,
child: ListTile(
contentPadding: const EdgeInsets.only(
left: 10,
right: 10,
top: 5,
),
leading: CircleAvatar(
backgroundColor: primaryColor,
backgroundImage: NetworkImage(item.prodImgUrl),
),
title: Text(
item.prodName,
style: const TextStyle(
fontSize: 16,
child: GestureDetector(
onTap: () async{
await FirebaseFirestore.instance
.collection('products')
.doc(item.docId)
.get().then((value) =>

Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DetailsScreen(product: value),
),
)
);
},
child: ListTile(
contentPadding: const EdgeInsets.only(
left: 10,
right: 10,
top: 5,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('\$${item.totalPrice}'),
const SizedBox(height: 5),
Row(
children: [
GestureDetector(
onTap: () => increaseQuantity(item.id),
child: const Icon(
Icons.add,
color: primaryColor,
leading: CircleAvatar(
backgroundColor: primaryColor,
backgroundImage: NetworkImage(item.prodImgUrl),
),
title: Text(
item.prodName,
style: const TextStyle(
fontSize: 16,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('\$${item.totalPrice}'),
const SizedBox(height: 5),
Row(
children: [
GestureDetector(
onTap: () => increaseQuantity(item.id),
child: const Icon(
Icons.add,
color: primaryColor,
),
),
),
const SizedBox(width: 10),
Text(
item.quantity.toString(),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
const SizedBox(width: 10),
Text(
item.quantity.toString(),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
const SizedBox(width: 10),
GestureDetector(
onTap: () => reduceQuantity(item.id),
child: const Icon(
Icons.remove,
color: primaryColor,
const SizedBox(width: 10),
GestureDetector(
onTap: () => reduceQuantity(item.id),
child: const Icon(
Icons.remove,
color: primaryColor,
),
),
),
],
],
),
],
),
trailing: IconButton(
onPressed: () => removeFromCart(item.prodId),
icon: const Icon(
Icons.delete_forever,
color: primaryColor,
),
],
),
trailing: IconButton(
onPressed: () => removeFromCart(item.prodId),
icon: const Icon(
Icons.delete_forever,
color: primaryColor,
),
),
),
Expand Down
3 changes: 3 additions & 0 deletions lib/utilities/products_stream_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ProductStreamBuilder extends StatelessWidget {

// add to cart
void addToCart(
var docId,
var prodId,
var prodName,
var prodPrice,
Expand All @@ -37,6 +38,7 @@ class ProductStreamBuilder extends StatelessWidget {
cartData.addToCart(
CartItem(
id: '',
docId: docId,
prodId: prodId,
prodName: prodName,
prodPrice: double.parse(prodPrice),
Expand Down Expand Up @@ -185,6 +187,7 @@ class ProductStreamBuilder extends StatelessWidget {
removeFromCart(data['prod_id']);
} else {
addToCart(
data.id,
data['prod_id'],
data['title'],
data['price'],
Expand Down
1 change: 1 addition & 0 deletions lib/views/main/customer/cart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class _CartScreenState extends State<CartScreen> {
color: primaryColor,
),
),
showBadge: cartData.cartItems.isNotEmpty ? true:false,
child: const Icon(
Icons.shopping_bag_outlined,
size: 30,
Expand Down
24 changes: 13 additions & 11 deletions lib/views/main/customer/customer_bottomNav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,38 @@ class _CustomerBottomNavState extends State<CustomerBottomNav> {
initialActiveIndex: currentPageIndex,
style: TabStyle.reactCircle,
items: [
TabItem(
const TabItem(
icon: Icons.house_siding,
),
TabItem(
const TabItem(
icon: Icons.favorite_border,
),
TabItem(
const TabItem(
icon: Icons.category_outlined,
),
TabItem(
const TabItem(
icon: Icons.storefront,
),
TabItem(
icon: Consumer<CartData>(
builder: (context, data, child) => Badge(
badgeContent: Text(
cartData.cartItemCount.toString(),
style: const TextStyle(
color: primaryColor,
),
),
child: Icon(
cartData.cartItemCount.toString(),
style: const TextStyle(
color: primaryColor,
),
)
,
showBadge: cartData.cartItems.isNotEmpty ? true:false,
child: Icon(
Icons.shopping_bag_outlined,
size: currentPageIndex == 4 ? 40 : 25,
color: currentPageIndex == 4 ? primaryColor : Colors.white70,
),
),
),
),
TabItem(
const TabItem(
icon: Icons.person_outline,
)
],
Expand Down
21 changes: 14 additions & 7 deletions lib/views/main/customer/order.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../constants/colors.dart';
Expand All @@ -23,7 +24,6 @@ class CustomerOrderScreen extends StatelessWidget {
orderData.removeFromOrder(id);
}


// pay through stripe
void payNow() async {
// TODO: Implement Pay now
Expand Down Expand Up @@ -231,12 +231,19 @@ class CustomerOrderScreen extends StatelessWidget {
),
subtitle: Text('\$${subData.totalPrice}'),
trailing: IconButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
DetailsScreen(product: subData),
),
),
onPressed: () async {
await FirebaseFirestore.instance
.collection('products')
.doc(subData.docId)
.get()
.then((value) =>
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
DetailsScreen(product: value),
),
));
},
icon: const Icon(
Icons.chevron_right,
color: primaryColor,
Expand Down
3 changes: 2 additions & 1 deletion lib/views/main/product/details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ class _DetailsScreenState extends State<DetailsScreen>
cartData.addToCart(
CartItem(
id: '',
prodId: product.prod_id,
docId: product.id,
prodId: product['prod_id'],
prodName: product['title'],
prodPrice: double.parse(product['price']),
prodImgUrl: product['images'][0],
Expand Down
File renamed without changes
Binary file added screenshots/New folder/cart_number.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 7a495ad

Please sign in to comment.