-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcart_screen.dart
111 lines (105 loc) · 3.3 KB
/
cart_screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import 'package:aba_payment/aba_payment.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../config.dart';
class CartScreen extends StatefulWidget {
@override
_CartScreenState createState() => _CartScreenState();
}
class _CartScreenState extends State<CartScreen> {
bool _isLoading = false;
ABAMerchant _merchant = merchant;
double _total = 6.00;
double _shipping = 0.0;
String _firstname = "Miss";
String _lastname = "My Lekha";
String _phone = "010464144";
String _email = "support@mylekha.app";
String _checkoutApiUrl =
"http://localhost/api/v1/integrate/payway/checkout_page";
List<ABATransactionItem> _items = [];
initialize() {
if (mounted) {
setState(() {
_total = 6.00;
_shipping = 0.0;
_firstname = "Miss";
_lastname = "My Lekha";
_phone = "010464144";
_email = "support@mylekha.app";
_items = [
ABATransactionItem(name: "ទំនិញ 1", price: 1, quantity: 1),
ABATransactionItem(name: "ទំនិញ 2", price: 2, quantity: 1),
ABATransactionItem(name: "ទំនិញ 3", price: 3, quantity: 1),
];
});
}
}
@override
void initState() {
super.initState();
initialize();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("YOUT CARTS (${_items.length})"),
),
body: Column(
children: [
Expanded(
child: ListView(
children: [
..._items.map(
(item) => ListTile(
title: Text("${item.name}"),
subtitle: Text("price: x${item.price}\$"),
trailing: Text("${item.quantity}"),
),
),
],
),
),
Divider(),
ABACheckoutContainer(
amount: _total,
shipping: _shipping,
firstname: _firstname,
lastname: _lastname,
email: _email,
phone: _phone,
items: _items,
checkoutApiUrl: _checkoutApiUrl,
merchant: _merchant,
onBeginCheckout: (transaction) {
setState(() => _isLoading = true);
EasyLoading.show(status: 'loading...');
},
onFinishCheckout: (transaction) {
setState(() => _isLoading = false);
EasyLoading.dismiss();
},
onBeginCheckTransaction: (transaction) {
setState(() => _isLoading = true);
EasyLoading.show(status: 'loading...');
print("onBeginCheckTransaction ${transaction!.toMap()}");
},
onFinishCheckTransaction: (transaction) {
setState(() => _isLoading = false);
EasyLoading.dismiss();
print("onFinishCheckTransaction ${transaction!.toMap()}");
},
enabled: !_isLoading,
// onPaymentFail: (transaction) {
// print("onPaymentFail ${transaction.toMap()}");
// },
onPaymentSuccess: (transaction) {
print("onPaymentSuccess ${transaction!.toMap()}");
},
),
],
),
);
}
}