Skip to content

Commit 7c140a9

Browse files
stash applied
1 parent bb53107 commit 7c140a9

File tree

16 files changed

+191
-124
lines changed

16 files changed

+191
-124
lines changed

lib/consts/strings.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const loggedin = "Logged in successfully";
1818
const loggedout = "Logged ou successfully";
1919
const updated = "Updated";
2020
const typeMessage = "Type a message...";
21+
const orderPlaced = "Order placed";
2122

2223
const createNewAccount = "or, create new account";
2324
const loginWith = "Log in with";

lib/controllers/cart_controller.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CartCotroller extends GetxController {
1818

1919
late dynamic productSnapshot;
2020
var products = [];
21+
var placingOrder = false.obs;
2122

2223
// calculate total price of item present in cart
2324
calculateTotalPrice(data) {
@@ -35,6 +36,7 @@ class CartCotroller extends GetxController {
3536

3637
// order placing
3738
placeMyOrder({required orderPaymentMethod, required totalAmount}) async {
39+
placingOrder(true);
3840
await getProductDetails();
3941

4042
await firestore.collection(ordersCollection).doc().set({
@@ -57,6 +59,8 @@ class CartCotroller extends GetxController {
5759
'total_amount': totalAmount,
5860
'orders': FieldValue.arrayUnion(products),
5961
});
62+
63+
placingOrder(false);
6064
}
6165

6266
// product details
@@ -66,9 +70,18 @@ class CartCotroller extends GetxController {
6670
products.add({
6771
'color': productSnapshot[i]['color'],
6872
'image': productSnapshot[i]['image'],
73+
'vendor_id': productSnapshot[i]['vendor_id'],
74+
'total_price': productSnapshot[i]['total_price'],
6975
'quantity': productSnapshot[i]['quantity'],
7076
'title': productSnapshot[i]['title'],
7177
});
7278
}
7379
}
80+
81+
// clear cart
82+
clearCart() {
83+
for (var i = 0; i < productSnapshot.length; i++) {
84+
firestore.collection(cartCollection).doc(productSnapshot[i].id).delete();
85+
}
86+
}
7487
}

lib/controllers/home_controller.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class HomeController extends GetxController {
1818
.where('id', isEqualTo: currentUser!.uid)
1919
.get()
2020
.then((value) {
21-
if (value.docs.isNotEmpty) return value.docs.single['name'];
21+
if (value.docs.isNotEmpty) {
22+
return value.docs.single['name'];
23+
}
2224
});
23-
2425
userName = n;
2526
}
2627
}

lib/controllers/product_controller.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ProductController extends GetxController {
4646
color,
4747
quantity,
4848
totalPrice,
49+
vendorId,
4950
context,
5051
}) async {
5152
await firestore.collection(cartCollection).doc().set({
@@ -55,6 +56,7 @@ class ProductController extends GetxController {
5556
'color': color,
5657
'quantity': quantity,
5758
'total_price': totalPrice,
59+
'vendor_id': vendorId,
5860
'added_by': currentUser!.uid
5961
}).onError(
6062
(error, stackTrace) => VxToast.show(context, msg: error.toString()));

lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ class MainApp extends StatelessWidget {
3333
);
3434
}
3535
}
36+
37+

lib/services/firestore_service.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,22 @@ class FirestoreService {
3030
.collection(messagesCollection)
3131
.orderBy('created_on', descending: false)
3232
.snapshots();
33+
34+
// get all orders
35+
static getAllOrders() => firestore
36+
.collection(ordersCollection)
37+
.where('order_by', isEqualTo: currentUser!.uid)
38+
.snapshots();
39+
40+
// get wishlist items
41+
static getWishlistItems() => firestore
42+
.collection(productsCollection)
43+
.where('p_wishlist', arrayContains: currentUser!.uid)
44+
.snapshots();
45+
46+
// get all messages
47+
static getAllMessages() => firestore
48+
.collection(chatsCollection)
49+
.where('fromId', isEqualTo: currentUser!.uid)
50+
.snapshots();
3351
}

lib/views/cart_screen_view/cart_screen.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ class CartScreen extends StatelessWidget {
4646
child: ListView.builder(
4747
itemCount: data.length,
4848
itemBuilder: (context, index) => ListTile(
49-
leading: Image.network("${data[index]['image']}"),
49+
leading: Image.network(
50+
"${data[index]['image']}",
51+
width: 80,
52+
fit: BoxFit.cover,
53+
),
5054
title:
5155
"${data[index]['title']} (x${data[index]['quantity']})"
5256
.text

lib/views/cart_screen_view/payment_screen.dart

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
// ignore_for_file: use_build_context_synchronously
2+
13
import 'package:emart/common_widgets/custom_button.dart';
4+
import 'package:emart/common_widgets/loading_indicator.dart';
25
import 'package:emart/consts/consts.dart';
36
import 'package:emart/consts/list.dart';
47
import 'package:emart/controllers/cart_controller.dart';
8+
import 'package:emart/views/home_view/home.dart';
59
import 'package:get/get.dart';
610

711
class PaymentScreen extends StatelessWidget {
@@ -70,19 +74,26 @@ class PaymentScreen extends StatelessWidget {
7074
),
7175
),
7276
),
73-
bottomNavigationBar: SizedBox(
74-
height: 60,
75-
child: customButton(
76-
onPressed: () {
77-
controller.placeMyOrder(
78-
orderPaymentMethod:
79-
paymentMethhodsList[controller.paymentIndex.value],
80-
totalAmount: controller.totalPrice.value,
81-
);
82-
},
83-
color: redColor,
84-
textColor: whiteColor,
85-
title: "Place my Order",
77+
bottomNavigationBar: Obx(
78+
() => SizedBox(
79+
height: 60,
80+
child: controller.placingOrder.value
81+
? loadingIndicator()
82+
: customButton(
83+
onPressed: () async {
84+
await controller.placeMyOrder(
85+
orderPaymentMethod:
86+
paymentMethhodsList[controller.paymentIndex.value],
87+
totalAmount: controller.totalPrice.value,
88+
);
89+
await controller.clearCart();
90+
VxToast.show(context, msg: orderPlaced);
91+
Get.offAll(() => Home());
92+
},
93+
color: redColor,
94+
textColor: whiteColor,
95+
title: "Place my Order",
96+
),
8697
),
8798
),
8899
);

lib/views/category_screen_view/item_details.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ class ItemDetails extends StatelessWidget {
347347
sellerName: data['p_seller'],
348348
title: data['p_name'],
349349
totalPrice: controller.totalPrice.value,
350+
vendorId: data['vendor_id'],
350351
context: context,
351352
);
352353
VxToast.show(context, msg: "Added to Cart");

lib/views/chat_screen_view/message_screen.dart

Whitespace-only changes.

0 commit comments

Comments
 (0)