Skip to content

Commit

Permalink
task: working on displaying order items for sellers
Browse files Browse the repository at this point in the history
  • Loading branch information
Atuoha committed Oct 13, 2022
1 parent 03749cd commit a838b58
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/models/cart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class CartItem {
final String id;
final dynamic docId;
final String sellerId;
final String userId;
final String prodId;
final String prodName;
final String prodImgUrl;
Expand All @@ -13,6 +14,7 @@ class CartItem {
required this.id,
required this.docId,
required this.sellerId,
required this.userId,
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(),
userId: cart.userId,
docId: cart.docId,
prodId: cart.prodId,
sellerId: cart.sellerId,
Expand Down
21 changes: 19 additions & 2 deletions lib/providers/order.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:multivendor_shop/models/order.dart';

import '../models/cart.dart';

class OrderData extends ChangeNotifier {
var totalPrice = 0.0;

Expand All @@ -16,8 +18,23 @@ class OrderData extends ChangeNotifier {
notifyListeners();
}

void pullSpecificOrders(String id){

var _totalOrderAmount = 0.0;

List<CartItem> pullSpecificOrders(String id) {
List<CartItem> items = [];
for (var order in _orderItems) {
for (var item in order.items) {
if (item.sellerId == id) {
items.add(item);
_totalOrderAmount += item.prodPrice;
}
}
}
return items;
}

get totalOrderAmount {
return _totalOrderAmount;
}

void removeFromOrder(String id) {
Expand Down
3 changes: 3 additions & 0 deletions lib/utilities/products_stream_builder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:multivendor_shop/views/main/product/details.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -26,6 +27,7 @@ class ProductStreamBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
var cartData = Provider.of<CartData>(context, listen: false);
var userId = FirebaseAuth.instance.currentUser!.uid;

// add to cart
void addToCart(
Expand All @@ -42,6 +44,7 @@ class ProductStreamBuilder extends StatelessWidget {
docId: docId,
prodId: prodId,
sellerId: sellerId,
userId: userId,
prodName: prodName,
prodPrice: double.parse(prodPrice),
prodImgUrl: prodImgUrl,
Expand Down
4 changes: 3 additions & 1 deletion lib/views/main/product/details.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:carousel_slider/carousel_slider.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:multivendor_shop/components/loading.dart';
Expand Down Expand Up @@ -137,7 +138,7 @@ class _DetailsScreenState extends State<DetailsScreen>
@override
Widget build(BuildContext context) {
var cartData = Provider.of<CartData>(context, listen: false);

var userId = FirebaseAuth.instance.currentUser!.uid;
// add to cart
void addToCart() {
var product = widget.product;
Expand All @@ -146,6 +147,7 @@ class _DetailsScreenState extends State<DetailsScreen>
id: '',
docId: product.id,
prodId: product['prod_id'],
userId: userId,
sellerId: product['seller_id'],
prodName: product['title'],
prodPrice: double.parse(product['price']),
Expand Down
71 changes: 71 additions & 0 deletions lib/views/main/seller/dashboard_screens/orders.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:multivendor_shop/providers/order.dart';
import 'package:provider/provider.dart';
import '../../../../constants/colors.dart';

class OrdersScreen extends StatefulWidget {
static const routeName = '/orders';

const OrdersScreen({Key? key}) : super(key: key);

@override
State<OrdersScreen> createState() => _OrdersScreenState();
}

class _OrdersScreenState extends State<OrdersScreen> {
var userId = FirebaseAuth.instance.currentUser!.uid;

@override
Widget build(BuildContext context) {
final orderData = Provider.of<OrderData>(context, listen: false);
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
Expand All @@ -33,6 +40,70 @@ class _OrdersScreenState extends State<OrdersScreen> {
),
),
),
body: Consumer<OrderData>(
builder: (
context,
data,
child,
) {
if (data.pullSpecificOrders(userId).isEmpty) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/sad.png'),
const SizedBox(height: 10),
const Text(
'No order to display',
style: TextStyle(
color: primaryColor,
fontWeight: FontWeight.bold,
),
)
],
);
}

return ListView.builder(
itemCount: data.pullSpecificOrders(userId).length,
itemBuilder: (context, index) {
var item = data.pullSpecificOrders(userId)[index];

return ListTile();
},
);
},
),
bottomSheet: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
const Text(
'Total:',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 22,
),
),
const SizedBox(width: 5),
Text(
'\$${orderData.totalOrderAmount}',
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 28,
color: primaryColor,
),
),
],
),

],
),
),
);
}
}
5 changes: 5 additions & 0 deletions lib/views/main/seller/seller_bottomNav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/services.dart';
import 'package:multivendor_shop/constants/colors.dart';
import 'package:multivendor_shop/views/main/customer/cart.dart';
import 'dashboard.dart';
import 'home.dart';
import 'profile.dart';
Expand All @@ -24,6 +25,7 @@ class _SellerBottomNavState extends State<SellerBottomNav> {
DashboardScreen(),
const CategoryScreen(),
const StoreScreen(),
const CartScreen(),
const ProfileScreen(),
];

Expand Down Expand Up @@ -62,6 +64,9 @@ class _SellerBottomNavState extends State<SellerBottomNav> {
),
TabItem(
icon: Icons.storefront,
),
TabItem(
icon: Icons.shopping_cart_outlined,
),
TabItem(
icon: Icons.person_outline,
Expand Down
Binary file added orders_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a838b58

Please sign in to comment.