76
77
final left = (parentWidth - effectiveCardWidth) / 2.0;
78
79
+ final isSelected = _selectedIndex == visualIndex;
80
+ final accounts = widget.accountListViewModel?.accounts;
81
+ final cardLabel = (accounts != null && realIndex < accounts.length)
82
+ ? accounts[realIndex].label
83
+ : S.of(context).balance;
84
+
85
+ void onCardTap() {
86
+ // printV(visualIndex);
87
+ if (compactMode && visualIndex != 0) {
88
+ widget.onCompactModeBackgroundCardsTapped();
89
+ } else if (!compactMode) {
90
+ setState(() {
91
+ if (widget.accountListViewModel != null)
92
+ widget.accountListViewModel!.select(widget.accountListViewModel!.accounts[realIndex]);
93
+ _selectedIndex = visualIndex;
94
+ });
95
+ }
96
+ }
97
+
98
+ void onCardLongPress() {
99
+ if (_selectedIndex == visualIndex) {
100
+ widget.dashboardViewModel.balanceViewModel.switchBalanceValue();
101
+ }
102
+ HapticFeedback.heavyImpact();
103
+ }
104
+
105
return AnimatedPositioned(
106
key: ValueKey("$visualIndex $realIndex"),
107
duration: animDuration,
112
duration: animDuration,
113
curve: Curves.easeOut,
114
scale: scale,
89
- child: GestureDetector(
90
- onTap: () {
91
- // printV(visualIndex);
92
- if (compactMode && visualIndex != 0) {
93
- widget.onCompactModeBackgroundCardsTapped();
94
- } else if (!compactMode) {
95
- setState(() {
96
- if (widget.accountListViewModel != null)
97
- widget.accountListViewModel!
98
- .select(widget.accountListViewModel!.accounts[realIndex]);
99
- _selectedIndex = visualIndex;
100
- });
101
- }
102
- },
103
- onLongPress: () {
104
- if (_selectedIndex == visualIndex) {
105
- widget.dashboardViewModel.balanceViewModel.switchBalanceValue();
106
- }
107
- ;
108
- HapticFeedback.heavyImpact();
109
- },
110
- child: Observer(builder: (_) {
111
- if (realIndex >= (widget.accountListViewModel?.accounts.length ?? 1)) {
112
- return Container();
113
- }
114
- final account = widget.accountListViewModel?.accounts[realIndex];
115
-
116
- // The second balance should always be the lightning balance
117
- // printV(widget.dashboardViewModel.balanceViewModel.formattedBalances.first.availableBalance);
118
- final walletBalanceRecord = widget.dashboardViewModel.balanceViewModel
119
- .getMainBalanceRecord(widget.lightningMode);
120
-
121
- late final String walletBalance;
122
- late final String walletFiatBalance;
123
- if (widget.dashboardViewModel.mwebEnabled && widget.dashboardViewModel.hasMweb) {
124
- if (widget.dashboardViewModel.balanceViewModel.displayMode ==
125
- BalanceDisplayMode.hiddenBalance) {
126
- walletBalance = '●●●●●●';
127
- walletFiatBalance = '●●●●●●';
115
+ // The card is the tap target; the balances and the card's own buttons stay
116
+ // reachable as children of this node.
117
+ child: Semantics(
118
+ button: true,
119
+ selected: isSelected,
120
+ label: cardLabel,
121
+ hint: isSelected
122
+ ? (widget.dashboardViewModel.balanceViewModel.displayMode ==
123
+ BalanceDisplayMode.hiddenBalance
124
+ ? S.of(context).long_press_show_balance
125
+ : S.of(context).long_press_hide_balance)
126
+ : null,
127
+ onTap: onCardTap,
128
+ onLongPress: isSelected ? onCardLongPress : null,
129
+ child: GestureDetector(
130
+ excludeFromSemantics: true,
131
+ onTap: onCardTap,
132
+ onLongPress: onCardLongPress,
133
+ child: Observer(builder: (_) {
134
+ if (realIndex >= (widget.accountListViewModel?.accounts.length ?? 1)) {
135
+ return Container();
136
+ }
137
+ final account = widget.accountListViewModel?.accounts[realIndex];
138
+
139
+ // The second balance should always be the lightning balance
140
+ // printV(widget.dashboardViewModel.balanceViewModel.formattedBalances.first.availableBalance);
141
+ final walletBalanceRecord = widget.dashboardViewModel.balanceViewModel
142
+ .getMainBalanceRecord(widget.lightningMode);
143
+
144
+ late final String walletBalance;
145
+ late final String walletFiatBalance;
146
+ if (widget.dashboardViewModel.mwebEnabled && widget.dashboardViewModel.hasMweb) {
147
+ if (widget.dashboardViewModel.balanceViewModel.displayMode ==
148
+ BalanceDisplayMode.hiddenBalance) {
149
+ walletBalance = '●●●●●●';
150
+ walletFiatBalance = '●●●●●●';
151
+ } else {
152
+ walletBalance = walletBalanceRecord?.combinedAvailableBalance ?? "0";
153
+ walletFiatBalance = walletBalanceRecord?.combinedFiatAvailableBalance ?? "0.00";
154
+ }
155
+ } else if (widget.dashboardViewModel.balanceViewModel.showCombinedBalance) {
156
+ walletBalance = "";
157
+ walletFiatBalance = widget.dashboardViewModel.balanceViewModel.combinedFiatBalance;
158
} else {
129
- walletBalance = walletBalanceRecord?.combinedAvailableBalance ?? "0";
130
- walletFiatBalance = walletBalanceRecord?.combinedFiatAvailableBalance ?? "0.00";
159
+ walletBalance = walletBalanceRecord?.availableBalance ?? "0";
160
+ walletFiatBalance = walletBalanceRecord?.fiatAvailableBalance ?? "0.00";
161
}
132
- } else if (widget.dashboardViewModel.balanceViewModel.showCombinedBalance) {
133
- walletBalance = "";
134
- walletFiatBalance = widget.dashboardViewModel.balanceViewModel.combinedFiatBalance;
135
- } else {
136
- walletBalance = walletBalanceRecord?.availableBalance ?? "0";
137
- walletFiatBalance = walletBalanceRecord?.fiatAvailableBalance ?? "0.00";
138
- }
139
-
140
- // the card designs is empty if widget gets built before it loads.
141
- // should get populated before user sees anything
142
- final CardDesign cardDesign;
143
- if (widget.dashboardViewModel.cardDesigns.isEmpty ||
144
- realIndex >= widget.dashboardViewModel.cardDesigns.length)
145
- cardDesign = CardDesign.genericDefault;
146
- else if (widget.lightningMode)
147
- cardDesign = widget.dashboardViewModel.cardDesigns[realIndex + 1];
148
- else
149
- cardDesign = widget.dashboardViewModel.cardDesigns[realIndex];
150
-
151
- final String accountName;
152
- final String accountBalance;
153
- if (account == null) {
154
- accountName = "";
155
- accountBalance = "";
156
- } else {
157
- accountName = account.label;
158
- accountBalance = account.balance ?? "0.00";
159
- }
160
-
161
- final assetName = widget.dashboardViewModel.balanceViewModel.showCombinedBalance
162
- ? ""
163
- : walletBalanceRecord?.formattedAssetTitle ?? assetTitleFallback;
164
-
165
- final List<BalanceCardAction> actions = widget.lightningMode
166
- ? [
167
- BalanceCardAction(
168
- label: S.current.bitcoin_lightning_deposit,
169
- icon: Icons.arrow_downward,
170
- onTap: depositToL2,
171
- ),
172
- BalanceCardAction(
173
- label: S.current.bitcoin_lightning_withdraw,
174
- icon: Icons.arrow_upward,
175
- onTap: withdrawFromL2,
176
- )
177
- ]
178
- : widget.dashboardViewModel.isEnabledTradeAction
179
- ? [
180
- BalanceCardAction(
181
- label: S.current.buy,
182
- icon: Icons.arrow_forward_ios_rounded,
183
- iconSize: 12,
184
- onTap: () => Navigator.of(context).pushNamed(Routes.buySellPage),
185
- )
186
- ]
187
- : [];
188
-
189
- return BalanceCard(
190
- width: effectiveCardWidth,
191
- accountName: accountName,
192
- accountBalance: accountBalance,
193
- designSwitchDuration: Duration(milliseconds: 150),
194
- assetName: assetName,
195
- capitalizeAssetName: _shouldCapitalizeAssetName(),
196
- balance: walletBalance,
197
- fiatCurrencyTitle: walletBalanceRecord?.fiatCurrency?.title ??
198
- widget.dashboardViewModel.settingsStore.fiatCurrency.title,
199
- fiatFirst: widget.dashboardViewModel.balanceViewModel.showCombinedBalance,
200
- fiatBalance: walletFiatBalance,
201
- selected: _selectedIndex == visualIndex,
202
- onCustomizeTapped: _selectedIndex == visualIndex ? widget.onCustomizeTapped : null,
203
- design: cardDesign,
204
- actions: actions,
205
- );
206
- }),
162
+
163
+ // the card designs is empty if widget gets built before it loads.
164
+ // should get populated before user sees anything
165
+ final CardDesign cardDesign;
166
+ if (widget.dashboardViewModel.cardDesigns.isEmpty ||
167
+ realIndex >= widget.dashboardViewModel.cardDesigns.length)
168
+ cardDesign = CardDesign.genericDefault;
169
+ else if (widget.lightningMode)
170
+ cardDesign = widget.dashboardViewModel.cardDesigns[realIndex + 1];
171
+ else
172
+ cardDesign = widget.dashboardViewModel.cardDesigns[realIndex];
173
+
174
+ final String accountName;
175
+ final String accountBalance;
176
+ if (account == null) {
177
+ accountName = "";
178
+ accountBalance = "";
179
+ } else {
180
+ accountName = account.label;
181
+ accountBalance = account.balance ?? "0.00";
182
+ }
183
+
184
+ final assetName = widget.dashboardViewModel.balanceViewModel.showCombinedBalance
185
+ ? ""
186
+ : walletBalanceRecord?.formattedAssetTitle ?? assetTitleFallback;
187
+
188
+ final List<BalanceCardAction> actions = widget.lightningMode
189
+ ? [
190
+ BalanceCardAction(
191
+ label: S.current.bitcoin_lightning_deposit,
192
+ icon: Icons.arrow_downward,
193
+ onTap: depositToL2,
194
+ ),
195
+ BalanceCardAction(
196
+ label: S.current.bitcoin_lightning_withdraw,
197
+ icon: Icons.arrow_upward,
198
+ onTap: withdrawFromL2,
199
+ )
200
+ ]
201
+ : widget.dashboardViewModel.isEnabledTradeAction
202
+ ? [
203
+ BalanceCardAction(
204
+ label: S.current.buy,
205
+ icon: Icons.arrow_forward_ios_rounded,
206
+ iconSize: 12,
207
+ onTap: () => Navigator.of(context).pushNamed(Routes.buySellPage),
208
+ )
209
+ ]
210
+ : [];
211
+
212
+ return BalanceCard(
213
+ width: effectiveCardWidth,
214
+ accountName: accountName,
215
+ accountBalance: accountBalance,
216
+ designSwitchDuration: Duration(milliseconds: 150),
217
+ assetName: assetName,
218
+ capitalizeAssetName: _shouldCapitalizeAssetName(),
219
+ balance: walletBalance,
220
+ fiatCurrencyTitle: walletBalanceRecord?.fiatCurrency?.title ??
221
+ widget.dashboardViewModel.settingsStore.fiatCurrency.title,
222
+ fiatFirst: widget.dashboardViewModel.balanceViewModel.showCombinedBalance,
223
+ fiatBalance: walletFiatBalance,
224
+ selected: _selectedIndex == visualIndex,
225
+ onCustomizeTapped: _selectedIndex == visualIndex ? widget.onCustomizeTapped : null,
226
+ design: cardDesign,
227
+ actions: actions,
228
+ );
229
+ }),
230
+ ),
231
),
232
),
233
);