Skip to content

Commit f0e50f8

Browse files
Set wishlish, order and cart count on Profile screen
1 parent f156908 commit f0e50f8

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

lib/services/firestore_service.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,29 @@ class FirestoreService {
4848
.collection(chatsCollection)
4949
.where('fromId', isEqualTo: currentUser!.uid)
5050
.snapshots();
51+
52+
// get cart, wishlist, and orders count
53+
static getCount() async => await Future.wait([
54+
firestore
55+
.collection(cartCollection)
56+
.where('added_by', isEqualTo: currentUser!.uid)
57+
.get()
58+
.then(
59+
(value) => value.docs.length,
60+
),
61+
firestore
62+
.collection(productsCollection)
63+
.where('p_wishlist', arrayContains: currentUser!.uid)
64+
.get()
65+
.then(
66+
(value) => value.docs.length,
67+
),
68+
firestore
69+
.collection(cartCollection)
70+
.where('order_by', isEqualTo: currentUser!.uid)
71+
.get()
72+
.then(
73+
(value) => value.docs.length,
74+
),
75+
]);
5176
}

lib/views/profile_screen_view/profile_screen.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,23 @@ class ProfileScreen extends StatelessWidget {
101101

102102
// cart
103103
20.heightBox,
104-
Row(
105-
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
106-
children: [
107-
cartDetails(context.screenWidth / 3.5, data['cart_count'],
108-
"in your cart"),
109-
cartDetails(context.screenWidth / 3.5,
110-
data['wishlist_count'], "in your wishlist"),
111-
cartDetails(context.screenWidth / 3.5, data['order_count'],
112-
"you ordered"),
113-
],
104+
FutureBuilder(
105+
future: FirestoreService.getCount(),
106+
builder: (BuildContext context, AsyncSnapshot snapshot) {
107+
if (!snapshot.hasData) return loadingIndicator();
108+
var countData = snapshot.data;
109+
return Row(
110+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
111+
children: [
112+
cartDetails(context.screenWidth / 3.5,
113+
countData[0].toString(), "in your cart"),
114+
cartDetails(context.screenWidth / 3.5,
115+
countData[1].toString(), "in your wishlist"),
116+
cartDetails(context.screenWidth / 3.5,
117+
countData[2].toString(), "you ordered"),
118+
],
119+
);
120+
},
114121
),
115122

116123
// profile button

0 commit comments

Comments
 (0)