This commit is contained in:
2023-02-26 17:37:04 -05:00
parent 9efce3ae85
commit 253940ae1e

View File

@@ -363,9 +363,7 @@ class _BuyScreenState extends State<BuyScreen> {
Flexible(flex: 2, child: ElevatedButton(onPressed: () {}, child: const Icon(Icons.filter_list))) Flexible(flex: 2, child: ElevatedButton(onPressed: () {}, child: const Icon(Icons.filter_list)))
]), ]),
), ),
Row( Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container( Container(
padding: EdgeInsets.only(left: 10, bottom: 10), padding: EdgeInsets.only(left: 10, bottom: 10),
child: Text( child: Text(
@@ -378,13 +376,12 @@ class _BuyScreenState extends State<BuyScreen> {
Container( Container(
padding: EdgeInsets.only(left: 10, bottom: 10), padding: EdgeInsets.only(left: 10, bottom: 10),
child: Text( child: Text(
"Time: "+dateFormat.format(DateTime.now()), "Time: " + dateFormat.format(DateTime.now()),
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
), ),
), ),
) )
]), ]),
Expanded( Expanded(
child: ListView.builder( child: ListView.builder(
@@ -407,8 +404,7 @@ class _BuyScreenState extends State<BuyScreen> {
return InkWell( return InkWell(
onTap: () { onTap: () {
showSheet(context, index, sellerName, price, data[index].availableTime.startTime.toDate(), data[index % data.length].availableTime.endTime.toDate(), showSheet(context, index, sellerName, price, data[index].availableTime.startTime.toDate(), data[index % data.length].availableTime.endTime.toDate(), _selectedLocation);
_selectedLocation);
// showDialog( // showDialog(
// context: context, // context: context,
// builder: (BuildContext context) => Dialog( // builder: (BuildContext context) => Dialog(
@@ -773,41 +769,60 @@ class _BuyScreenState extends State<BuyScreen> {
// add close button // add close button
ElevatedButton( ElevatedButton(
onPressed: () async { onPressed: () async {
try { try {
// 1. create payment intent on the server // 1. create payment intent on the server
int price = (SellerPrice*100).toInt(); int price = (SellerPrice * 100).toInt();
var Ddata = await http.get(Uri.parse("http://172.20.10.2:5000/payment-sheet?price=" + price.toString())); var Ddata = await http.get(Uri.parse("http://172.20.10.2:5000/payment-sheet?price=" + price.toString()));
var data = jsonDecode(Ddata.body); var data = jsonDecode(Ddata.body);
print("wtf"); print("wtf");
// 2. initialize the payment sheet
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
// Enable custom flow
customFlow: true,
// Main params
merchantDisplayName: 'RU SwipeTrade',
paymentIntentClientSecret: data['paymentIntent'],
// Customer keys
customerEphemeralKeySecret: data['ephemeralKey'],
customerId: data['customer'],
// Extra options
style: ThemeMode.dark,
),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: $e')),
);
rethrow;
}
await Stripe.instance.presentPaymentSheet();
Navigator.pop(context);
// 2. initialize the payment sheet
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
// Enable custom flow
customFlow: true,
// Main params
merchantDisplayName: 'RU SwipeTrade',
paymentIntentClientSecret: data['paymentIntent'],
// Customer keys
customerEphemeralKeySecret: data['ephemeralKey'],
customerId: data['customer'],
// Extra options
style: ThemeMode.dark,
),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: $e')),
);
rethrow;
}
await Stripe.instance.presentPaymentSheet();
Navigator.pop(context);
showDialog<String>(
context: context,
builder: (BuildContext context) => Dialog(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Your payment has gone through.'),
const SizedBox(height: 15),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
),
],
),
),
),
);
}, },
child: Text( child: Text(
"Purchase", "Purchase",