-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathaction_card.dart
More file actions
195 lines (184 loc) · 6.42 KB
/
Copy pathaction_card.dart
File metadata and controls
195 lines (184 loc) · 6.42 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import 'dart:io';
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:bb_mobile/core/widgets/text/text.dart';
import 'package:bb_mobile/features/buy/ui/buy_router.dart';
import 'package:bb_mobile/features/exchange/presentation/exchange_cubit.dart';
import 'package:bb_mobile/features/exchange/ui/exchange_router.dart';
import 'package:bb_mobile/features/pay/ui/pay_router.dart';
import 'package:bb_mobile/features/sell/ui/sell_router.dart';
import 'package:bb_mobile/features/settings/presentation/bloc/settings_cubit.dart';
import 'package:bb_mobile/features/swap/ui/swap_router.dart';
import 'package:bb_mobile/generated/flutter_gen/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:bull_ui/bull_ui.dart' show Gap;
import 'package:go_router/go_router.dart';
enum _ButtonPosition { first, last, middle }
class ActionCard extends StatelessWidget {
const ActionCard({super.key});
@override
Widget build(BuildContext context) {
return const _ActionRow();
}
}
class _ActionRow extends StatelessWidget {
const _ActionRow();
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: context.appColors.background,
border: Border(
bottom: BorderSide(color: context.appColors.outline, width: 1),
),
),
child: Material(
elevation: 2,
shadowColor: context.appColors.onSurface.withValues(alpha: 0.5),
color: context.appColors.transparent,
child: SizedBox(
height: 80,
child: Row(
children: [
_ActionButton(
icon: Assets.icons.btc.path,
label: context.loc.homeActionBuy,
onPressed: () {
if (Platform.isIOS) {
final isSuperuser =
context.read<SettingsCubit>().state.isSuperuser ??
false;
if (isSuperuser) {
context.pushNamed(BuyRoute.buy.name);
} else {
context.goNamed(ExchangeRoute.exchangeLanding.name);
}
} else {
context.pushNamed(BuyRoute.buy.name);
}
},
position: _ButtonPosition.first,
disabled: false,
),
const Gap(1),
_ActionButton(
icon: Assets.icons.dollar.path,
label: context.loc.homeActionSell,
onPressed: () {
if (Platform.isIOS) {
final isSuperuser =
context.read<SettingsCubit>().state.isSuperuser ??
false;
if (isSuperuser) {
context.pushNamed(SellRoute.sell.name);
} else {
context.goNamed(ExchangeRoute.exchangeLanding.name);
}
} else {
context.pushNamed(SellRoute.sell.name);
}
},
position: _ButtonPosition.middle,
disabled: false,
),
const Gap(1),
_ActionButton(
icon: Assets.icons.rightArrow.path,
label: context.loc.homeActionPay,
onPressed: () {
final notLoggedIn = context
.read<ExchangeCubit>()
.state
.notLoggedIn;
if (notLoggedIn) {
context.goNamed(ExchangeRoute.exchangeLanding.name);
} else {
if (Platform.isIOS) {
final isSuperuser =
context.read<SettingsCubit>().state.isSuperuser ??
false;
if (isSuperuser) {
context.pushNamed(PayRoute.pay.name);
} else {
context.goNamed(ExchangeRoute.exchangeLanding.name);
}
} else {
context.pushNamed(PayRoute.pay.name);
}
}
},
position: _ButtonPosition.middle,
disabled: false,
),
const Gap(1),
_ActionButton(
icon: Assets.icons.swap.path,
label: context.loc.homeActionTransfer,
onPressed: () {
context.pushNamed(SwapRoute.swap.name);
},
position: _ButtonPosition.last,
disabled: false,
),
],
),
),
),
);
}
}
class _ActionButton extends StatelessWidget {
const _ActionButton({
required this.icon,
required this.label,
required this.onPressed,
required this.position,
required this.disabled,
});
final String icon;
final String label;
final Function onPressed;
final _ButtonPosition position;
final bool disabled;
@override
Widget build(BuildContext context) {
const r = Radius.circular(2);
final radius = BorderRadius.only(
topLeft: position == _ButtonPosition.first ? r : Radius.zero,
topRight: position == _ButtonPosition.last ? r : Radius.zero,
bottomLeft: position == _ButtonPosition.first ? r : Radius.zero,
bottomRight: position == _ButtonPosition.last ? r : Radius.zero,
);
return Expanded(
child: InkWell(
onTap: disabled ? null : () => onPressed(),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 12),
decoration: BoxDecoration(
borderRadius: radius,
color: context.appColors.background,
backgroundBlendMode: disabled ? .darken : null,
),
child: Column(
spacing: 8,
mainAxisAlignment: .center,
children: [
Image.asset(
icon,
height: 24,
width: 24,
color: context.appColors.secondary,
),
BBText(
label,
style: context.font.bodyLarge,
color: context.appColors.secondary,
),
],
),
),
),
);
}
}