-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathwallet_home_top_section.dart
More file actions
254 lines (225 loc) · 7.15 KB
/
Copy pathwallet_home_top_section.dart
File metadata and controls
254 lines (225 loc) · 7.15 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
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/cards/action_card.dart';
import 'package:bb_mobile/features/bitcoin_price/presentation/cubit/price_chart_cubit.dart';
import 'package:bb_mobile/features/bitcoin_price/ui/currency_text.dart';
import 'package:bb_mobile/features/bitcoin_price/ui/price_chart_widget.dart';
import 'package:bb_mobile/features/settings/presentation/bloc/settings_cubit.dart';
import 'package:bb_mobile/features/transactions/ui/transactions_router.dart';
import 'package:bb_mobile/features/wallet/presentation/bloc/wallet_bloc.dart';
import 'package:bb_mobile/features/wallet/ui/widgets/eye_toggle.dart';
import 'package:bb_mobile/features/wallet/ui/widgets/home_fiat_balance.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';
import 'package:shimmer/shimmer.dart';
class WalletHomeTopSection extends StatelessWidget {
const WalletHomeTopSection({super.key});
/// Height of the dark area behind the balance (and the price chart, when it
/// is toggled on).
static const double _balanceAreaHeight = 264;
/// Distance from the top of the dark area down to the balance.
static const double _balanceTopSpacing = 123;
/// How far the [ActionCard] hangs below the dark area.
static const double _actionCardOverhang = 76;
/// Fixed height of the section.
static const double _height = _balanceAreaHeight + _actionCardOverhang;
@override
Widget build(BuildContext context) {
return const SizedBox(
height: _height,
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [SizedBox(height: _balanceAreaHeight, child: _UI())],
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 13.0),
child: ActionCard(),
),
),
],
),
);
}
}
class _UI extends StatefulWidget {
const _UI();
@override
State<_UI> createState() => _UIState();
}
class _UIState extends State<_UI> {
late Image image;
@override
void initState() {
image = Image.asset(Assets.backgrounds.bgRed.path, fit: BoxFit.fill);
super.initState();
}
@override
Widget build(BuildContext context) {
final showChart = context.select(
(PriceChartCubit cubit) => cubit.state.showChart,
);
return Stack(
fit: StackFit.expand,
children: [
AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
color: Colors.transparent,
child: image,
),
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
transitionBuilder: (child, animation) {
return SlideTransition(
position:
Tween<Offset>(
begin: const Offset(1.0, 0.0),
end: Offset.zero,
).animate(
CurvedAnimation(parent: animation, curve: Curves.easeInOut),
),
child: child,
);
},
child: showChart
? const _ChartView(key: ValueKey('chart'))
: const _Amounts(key: ValueKey('amounts')),
),
],
);
}
}
class _Amounts extends StatelessWidget {
const _Amounts({super.key});
@override
Widget build(BuildContext context) {
return const Column(
children: [
Gap(WalletHomeTopSection._balanceTopSpacing),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [Spacer(), _BtcTotalAmt(), Gap(16), EyeToggle(), Spacer()],
),
Gap(12),
_FiatAmt(),
Gap(8),
_UnconfirmedIncomingBalance(),
],
);
}
}
class _BtcTotalAmt extends StatelessWidget {
const _BtcTotalAmt();
@override
Widget build(BuildContext context) {
final walletState = context.select((WalletBloc bloc) => bloc.state);
final bitcoinUnit = context.select(
(SettingsCubit cubit) => cubit.state.bitcoinUnit,
);
final showSkeleton =
walletState.status == WalletStatus.initial ||
walletState.status == WalletStatus.loading ||
bitcoinUnit == null;
if (showSkeleton) {
return const _WalletHomeBtcAmountSkeleton();
}
final btcTotal = walletState.totalBalance();
return CurrencyText(
btcTotal,
showFiat: false,
style: context.font.displaySmall,
color: context.appColors.onPrimary,
);
}
}
class _FiatAmt extends StatelessWidget {
const _FiatAmt();
@override
Widget build(BuildContext context) {
final walletState = context.select((WalletBloc bloc) => bloc.state);
final showBalanceLoading =
walletState.status == WalletStatus.initial ||
walletState.status == WalletStatus.loading;
return HomeFiatBalance(
balanceSat: walletState.totalBalance(),
showBalanceLoading: showBalanceLoading,
);
}
}
class _WalletHomeBtcAmountSkeleton extends StatelessWidget {
const _WalletHomeBtcAmountSkeleton();
@override
Widget build(BuildContext context) {
return Shimmer.fromColors(
baseColor: context.appColors.shimmerBase,
highlightColor: context.appColors.shimmerHighlight,
child: SizedBox(
width: 200,
height: 40,
child: DecoratedBox(
decoration: BoxDecoration(
color: context.appColors.surface,
borderRadius: BorderRadius.circular(4),
),
),
),
);
}
}
class _ChartView extends StatelessWidget {
const _ChartView({super.key});
@override
Widget build(BuildContext context) {
return const PriceChartWidget();
}
}
class _UnconfirmedIncomingBalance extends StatelessWidget {
const _UnconfirmedIncomingBalance();
@override
Widget build(BuildContext context) {
final unconfirmed = context.select(
(WalletBloc bloc) => bloc.state.unconfirmedIncomingBalance,
);
if (unconfirmed == 0) return const SizedBox.shrink();
final color = context.appColors.onPrimary;
return GestureDetector(
onTap: () {
context.pushNamed(TransactionsRoute.transactions.name);
},
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.arrow_downward, color: color, size: 20),
CurrencyText(
unconfirmed,
showFiat: false,
style: context.font.bodyLarge,
color: color,
),
],
),
Align(
child: Text(
context.loc.walletBalanceUnconfirmedIncoming,
style: context.font.bodyLarge?.copyWith(color: color),
),
),
],
),
),
);
}
}