diff --git a/lib/screens/home/cartAndMenu/cart_list.dart b/lib/screens/home/cartAndMenu/cart_list.dart index f8170d8..46cfa29 100755 --- a/lib/screens/home/cartAndMenu/cart_list.dart +++ b/lib/screens/home/cartAndMenu/cart_list.dart @@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:readyuser/models/item.dart'; import 'package:readyuser/models/user.dart'; import 'package:readyuser/screens/home/cartAndMenu/item_tile.dart'; -import 'package:readyuser/screens/payment/upi_pay.dart'; +import 'package:readyuser/screens/payment/checkout.dart'; import 'package:readyuser/services/database.dart'; import 'package:readyuser/shared/constants.dart'; import 'package:readyuser/shared/loading.dart'; @@ -81,8 +81,10 @@ class _CartWidgetState extends State { onPressed: () async { print("yess"); //Navigator.pop(context); - - Navigator.push(context, CupertinoPageRoute(builder: (context) => PaymentPage())); + if(!myCart.isEmpty) + { + Navigator.push(context,MaterialPageRoute(builder: (context)=>checkoutpage())); + } //Navigator.pop(context); print("noo"); }, diff --git a/lib/screens/home/orderHistory/order_list.dart b/lib/screens/home/orderHistory/order_list.dart index 459b2d3..553465f 100644 --- a/lib/screens/home/orderHistory/order_list.dart +++ b/lib/screens/home/orderHistory/order_list.dart @@ -36,6 +36,7 @@ class _OrderWidgetState extends State { shrinkWrap: true, itemCount: data.length, itemBuilder: (context, index) { + print(data[index].id); return OrderTile( order: data[index], ); diff --git a/lib/screens/payment/checkout.dart b/lib/screens/payment/checkout.dart new file mode 100644 index 0000000..16ed79d --- /dev/null +++ b/lib/screens/payment/checkout.dart @@ -0,0 +1,157 @@ +import 'package:flutter/material.dart'; +import 'package:readyuser/models/item.dart'; +import 'package:readyuser/models/order.dart'; +import 'package:readyuser/screens/home/home.dart'; +import 'package:readyuser/services/database.dart'; +import 'package:readyuser/shared/constants.dart'; +import 'package:upi_india/upi_india.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:readyuser/models/item.dart'; +import 'package:readyuser/models/user.dart'; +import 'package:readyuser/screens/home/cartAndMenu/item_tile.dart'; +import 'package:readyuser/screens/payment/upi_pay.dart'; +import 'package:readyuser/services/database.dart'; +import 'package:readyuser/shared/constants.dart'; +import 'package:readyuser/shared/loading.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + + +class checkoutpage extends StatefulWidget { + @override + _checkoutpageState createState() => _checkoutpageState(); +} + +class _checkoutpageState extends State { + @override + Widget build(BuildContext context) { + double suma = 0.0; + User user = Provider.of(context); + print(user); + return StreamBuilder>( + stream: DatabaseService(uid: user.uid).cart, + builder: (context, snapshot) { + List data = snapshot.data; + + if (data == null) return Loading(); + myCart = new List.from(data); + print(myCart); + suma = 0.0; + myCart.forEach((element) {suma += element.cost*element.quantity;}); + userCartVal = suma; + print(suma); + + return Scaffold( + backgroundColor: Colors.brown[100], + appBar: AppBar( + backgroundColor: Colors.brown[400], + elevation: 0.0, + title: Text('Checkout Page') + ), + body:Column( + children: [ + Expanded( + child: StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return ListView.builder( + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: data.length, + itemBuilder: (context, index) { + return ItemTile( + item: data[index] + ); + }, + );} + ), + ), + SizedBox(height: 10.0), + Row( + children: [ + Expanded(child: Padding( + padding: const EdgeInsets.all(10.0), + child: Text( + "Total Cart Value:\n ${userCartVal}", + style: TextStyle( + color: Colors.pink[400], + fontWeight: FontWeight.bold, + fontSize: 20, + ), + textAlign: TextAlign.center, + ), + )), + Expanded( + child: Column( + children: [ + RaisedButton( + color: Colors.pink[400], + child: Text( + "Pay", + style: TextStyle(color: Colors.white), + ), + onPressed: () async { + print("yess"); + Navigator.pop(context); + Navigator.push(context, CupertinoPageRoute(builder: (context) => PaymentPage())); + //Navigator.pop(context); + print("noo"); + }, + ), + RaisedButton( + color: Colors.pink[400], + child: Text( + "Pay on Delivery", + style: TextStyle(color: Colors.white), + ), + onPressed: () async { + Map myMap = new Map(); + myMap = Map.fromIterable(myCart, key: (e) => e.id, value: (e) => {'cost':e.cost,'quantity':e.quantity, 'name':e.name}); + print(myMap); + List out = []; + myMap.forEach((key, value) => out.add(new Item(id: key, cost: value['cost'], quantity: value['quantity'], name: value['name']))); + print(out); + print('Transaction Successful'); + Order order = new Order( + status: "Order Placed", + cart: myMap?? '', + totalCost: userCartVal ?? '0.0', + user: userUid ?? '0', + vendor: userCartVendor ?? '0', + ); + print("order"); + DatabaseService(uid: userUid).addOrderData(order); + DatabaseService(uid: userUid).addOrderDataVendor(order); + showDialog( + context:context, + child: new AlertDialog( + title: new Text('Success!'), + content: new Text('Order placed successfully'), + actions: [ + new FlatButton( + child: Text("Payed"), + onPressed: () async{ + Navigator.of(context).pop(); + Navigator.of(context).pop(); + await DatabaseService(uid: userUid).clearCart(); + print('works'); + userCartVal = 0.0; + userCartVendor = ''; + }, + ) + ], + ), + ); + }, + ), + ], + ), + ), + ], + ) + ], + ), + ); + } + ); + } +} diff --git a/lib/screens/payment/upi_pay.dart b/lib/screens/payment/upi_pay.dart index 0165297..4766c1a 100644 --- a/lib/screens/payment/upi_pay.dart +++ b/lib/screens/payment/upi_pay.dart @@ -4,7 +4,7 @@ import 'package:readyuser/models/order.dart'; import 'package:readyuser/services/database.dart'; import 'package:readyuser/shared/constants.dart'; import 'package:upi_india/upi_india.dart'; - +import 'package:readyuser/screens/payment/checkout.dart'; class PaymentPage extends StatefulWidget { @override diff --git a/lib/services/database.dart b/lib/services/database.dart index 451d731..90c9a73 100755 --- a/lib/services/database.dart +++ b/lib/services/database.dart @@ -166,7 +166,7 @@ class DatabaseService { // brew list from snapshot List _orderListFromSnapshot(QuerySnapshot snapshot) { return snapshot.documents.map((doc){ - //print(doc.documentID); + print(doc.documentID); return Order( id: doc.documentID, cart: doc.data['cart'] ?? '',