Skip to content

Commit

Permalink
checkout page added
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshu-tiwari1502 committed Jun 20, 2020
1 parent e1a490f commit 7bc9559
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/screens/home/cartAndMenu/cart_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -81,8 +81,10 @@ class _CartWidgetState extends State<CartWidget> {
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");
},
Expand Down
1 change: 1 addition & 0 deletions lib/screens/home/orderHistory/order_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class _OrderWidgetState extends State<OrderWidget> {
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (context, index) {
print(data[index].id);
return OrderTile(
order: data[index],
);
Expand Down
157 changes: 157 additions & 0 deletions lib/screens/payment/checkout.dart
Original file line number Diff line number Diff line change
@@ -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<checkoutpage> {
@override
Widget build(BuildContext context) {
double suma = 0.0;
User user = Provider.of<User>(context);
print(user);
return StreamBuilder<List<Item>>(
stream: DatabaseService(uid: user.uid).cart,
builder: (context, snapshot) {
List<Item> 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: <Widget>[
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: <Widget>[
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: <Widget>[
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<String, dynamic> 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<Item> 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: <Widget>[
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 = '';
},
)
],
),
);
},
),
],
),
),
],
)
],
),
);
}
);
}
}
2 changes: 1 addition & 1 deletion lib/screens/payment/upi_pay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/services/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class DatabaseService {
// brew list from snapshot
List<Order> _orderListFromSnapshot(QuerySnapshot snapshot) {
return snapshot.documents.map((doc){
//print(doc.documentID);
print(doc.documentID);
return Order(
id: doc.documentID,
cart: doc.data['cart'] ?? '',
Expand Down

0 comments on commit 7bc9559

Please sign in to comment.