-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.dart
136 lines (128 loc) · 3.57 KB
/
main.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import 'package:example/shoe_card.dart';
import 'package:flutter/material.dart';
import 'event_handler.dart';
import 'payments/scaffold.dart';
import 'shoes.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final List<Shoe> _shoes = List.generate(5, (index) {
return Shoe(
amount: 100 * index,
currency: 'PHP',
name: 'Shoe #$index',
description: 'A smol shoe size of S-$index',
);
});
@override
void initState() {
super.initState();
}
double get _totalAmount => _cart.fold(0, (prev, curr) => prev + curr.amount);
final List<Shoe> _cart = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Tap to pay'),
),
drawer: Drawer(
child: ListView(
children: [
ListTile(
title: Text("Payments"),
onTap: () {
Navigator.push(context,
PageRouteBuilder(pageBuilder: (context, _, __) {
return PaymentScaffold();
}));
},
),
],
),
),
body: LayoutBuilder(builder: (context, constraints) {
return GridView.builder(
itemCount: _shoes.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
),
itemBuilder: (context, index) {
final shoe = _shoes[index];
return GestureDetector(
onTap: () {
setState(() {
if (!_cart.contains(shoe)) {
_cart.add(shoe);
}
});
},
child: ShoeCard(shoe: shoe),
);
},
);
}),
floatingActionButton: _totalAmount > 100
? FloatingActionButton.extended(
onPressed: () async {
await showModalBottomSheet(
context: context,
builder: (context) {
return PaymentOptionList(cart: _cart);
});
},
label: Text('Single Payment(${_cart.length})'),
icon: const Icon(Icons.credit_card),
)
: null,
);
}
}
class PaymentOptionList extends StatefulWidget {
const PaymentOptionList({Key? key, required this.cart}) : super(key: key);
final List<Shoe> cart;
@override
State<PaymentOptionList> createState() => _PaymentOptionListState();
}
class _PaymentOptionListState extends State<PaymentOptionList>
with PaymongoEventHandler {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
ListTile(
title: Text("GCash Payment"),
onTap: () async {
await gcashPayment(widget.cart);
},
),
ListTile(
title: Text("Credit/Debit Payment"),
onTap: () async {
await cardPayment(widget.cart);
},
),
ListTile(
title: Text('Grab Pay'),
onTap: () async {
await grabPayment(widget.cart);
},
),
ListTile(
title: Text("PayMaya Payment"),
onTap: () async {
await paymayaPayment(widget.cart);
},
),
],
),
);
}
}