Skip to content

Commit

Permalink
task: pulling orders from customers
Browse files Browse the repository at this point in the history
  • Loading branch information
Atuoha committed Oct 13, 2022
1 parent a838b58 commit a1718e5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
14 changes: 14 additions & 0 deletions lib/providers/order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class OrderData extends ChangeNotifier {
var _totalOrderAmount = 0.0;

List<CartItem> pullSpecificOrders(String id) {
_totalOrderAmount = 0.0;
List<CartItem> items = [];
for (var order in _orderItems) {
for (var item in order.items) {
Expand All @@ -37,6 +38,19 @@ class OrderData extends ChangeNotifier {
return _totalOrderAmount;
}

DateTime? getOrderDate(String id) {
DateTime? date;
for (var item in _orderItems) {
for (var cartItem in item.items) {
if (cartItem.id == id) {
date = item.orderDate;
}
}
}

return date;
}

void removeFromOrder(String id) {
var orderItem = _orderItems.firstWhere(
(item) => item.id == id,
Expand Down
1 change: 1 addition & 0 deletions lib/views/main/product/details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class _DetailsScreenState extends State<DetailsScreen>
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 Down
83 changes: 79 additions & 4 deletions lib/views/main/seller/dashboard_screens/orders.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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/providers/order.dart';
import 'package:provider/provider.dart';
import '../../../../constants/colors.dart';
import 'package:intl/intl.dart' as intl;

class OrdersScreen extends StatefulWidget {
static const routeName = '/orders';
Expand All @@ -17,9 +19,28 @@ class OrdersScreen extends StatefulWidget {
class _OrdersScreenState extends State<OrdersScreen> {
var userId = FirebaseAuth.instance.currentUser!.uid;

DataRow buildDataRow(String field, dynamic detail) {
return DataRow(
cells: [
DataCell(
Text(
field,
style: const TextStyle(color: Colors.grey),
),
),
DataCell(
Text(
detail,
style: const TextStyle(color: Colors.grey),
),
)
],
);
}

@override
Widget build(BuildContext context) {
final orderData = Provider.of<OrderData>(context, listen: false);
final orderData = Provider.of<OrderData>(context, listen: false);
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
Expand All @@ -33,7 +54,7 @@ class _OrdersScreenState extends State<OrdersScreen> {
appBar: AppBar(
backgroundColor: primaryColor,
title: const Text(
'Orders',
'My Orders',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
Expand Down Expand Up @@ -69,7 +90,62 @@ class _OrdersScreenState extends State<OrdersScreen> {
itemBuilder: (context, index) {
var item = data.pullSpecificOrders(userId)[index];

return ListTile();
var userDetails = FirebaseFirestore.instance
.collection('sellers')
.doc(item.userId)
.get();

var date = intl.DateFormat.yMMMEd()
.format(orderData.getOrderDate(item.id)!);
return ExpansionTile(
leading: CircleAvatar(
backgroundColor: primaryColor,
backgroundImage: NetworkImage(item.prodImgUrl),
),
title: Text(
item.prodName,
style: const TextStyle(
color: Colors.black,
),
),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Price: ${item.totalPrice}',
style: const TextStyle(
color: Colors.grey,
),
),
Text(
'Quantity: ${item.quantity}',
style: const TextStyle(
color: Colors.grey,
),
),
],
),
iconColor: primaryColor,
children: [
FutureBuilder<DocumentSnapshot>(
future: userDetails,
builder: (context, AsyncSnapshot<DocumentSnapshot>snapshot) => DataTable(
columns: const [
DataColumn(label: Text('Section')),
DataColumn(label: Text('Information'))
],
rows: [
buildDataRow('Order Date', date),
buildDataRow('Customer', snapshot.data!['fullname']),
buildDataRow(
'Billing Address', snapshot.data!['address']),
buildDataRow('Email', snapshot.data!['email']),
buildDataRow('Contact', snapshot.data!['phone']),
],
),
)
],
);
},
);
},
Expand Down Expand Up @@ -100,7 +176,6 @@ class _OrdersScreenState extends State<OrdersScreen> {
),
],
),

],
),
),
Expand Down

0 comments on commit a1718e5

Please sign in to comment.