dev
dart 182 lines 7.63 KB
Raw
1 import 'dart:math' show min;
2
3 import 'package:cake_wallet/new-ui/widgets/coins_page/assets_history/asset_details_modal.dart';
4 import 'package:cake_wallet/new-ui/widgets/coins_page/token_image_widget.dart';
5 import 'package:cake_wallet/src/screens/wallet_connect/utils/string_parsing.dart';
6 import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
7 import 'package:cw_core/wallet_base.dart';
8 import 'package:cw_core/wallet_type.dart';
9 import 'package:flutter/material.dart';
10
11 class AssetTile extends StatelessWidget {
12 const AssetTile(
13 {super.key,
14 required this.balance,
15 required this.chainIconPath,
16 this.showSecondary = false,
17 this.showBridgeButton = false,
18 this.title,
19 this.trailingText,
20 this.modalMode = AssetDetailsModalModes.normal,
21 required this.wallet,
22 required this.showSwap,
23 required this.isFirst,
24 required this.isLast});
25
26 final BalanceRecord balance;
27 final bool showSecondary;
28 final bool showSwap;
29 final bool showBridgeButton;
30 final String chainIconPath;
31 final String? title;
32 final String? trailingText;
33 final AssetDetailsModalModes modalMode;
34 final WalletBase wallet;
35 final bool isFirst;
36 final bool isLast;
37
38 @override
39 Widget build(BuildContext context) {
40 final iconPath = balance.asset.iconPath ?? "";
41
42 // The row is one control: name, amount and fiat value merge into a single
43 // button node that opens the asset details sheet.
44 return MergeSemantics(
45 child: Semantics(
46 button: true,
47 child: GestureDetector(
48 onTap: () {
49 showModalBottomSheet(
50 context: context,
51 isScrollControlled: true,
52 builder: (context) {
53 return AssetDetailsModal(
54 showSwap: showSwap,
55 showBridgeButton: showBridgeButton,
56 asset: balance.asset,
57 title: title ?? balance.asset.fullName ?? balance.asset.name,
58 chainTitle: "",
59 subtitle: trailingText ?? _getChainTitle(),
60 amount:
61 showSecondary ? balance.secondAvailableBalance : balance.availableBalance,
62 currencyTitle: balance.asset.title,
63 fiatAmount: showSecondary
64 ? balance.fiatSecondAvailableBalance
65 : balance.fiatAvailableBalance,
66 iconPath: balance.asset.iconPath ?? "",
67 chainIconPath: chainIconPath,
68 mode: modalMode,
69 wallet: wallet,
70 );
71 });
72 },
73 child: Padding(
74 padding: const EdgeInsets.symmetric(horizontal: 18.0),
75 child: Container(
76 width: double.infinity,
77 height: 72,
78 decoration: BoxDecoration(
79 color: Theme.of(context).colorScheme.surfaceContainer,
80 borderRadius: BorderRadius.vertical(
81 top: isFirst ? Radius.circular(18) : Radius.zero,
82 bottom: isLast ? Radius.circular(18) : Radius.zero,
83 ),
84 ),
85 child: Padding(
86 padding: const EdgeInsets.symmetric(horizontal: 12.0),
87 child: Row(
88 mainAxisSize: MainAxisSize.max,
89 mainAxisAlignment: MainAxisAlignment.spaceBetween,
90 children: [
91 Expanded(
92 child: Row(
93 mainAxisSize: MainAxisSize.min,
94 children: [
95 // Decorative: the asset name is already in the row text.
96 ExcludeSemantics(
97 child: iconPath.isNotEmpty
98 ? TokenImageWidget(
99 imageUrl: iconPath,
100 size: 36,
101 )
102 : Container(
103 width: 36,
104 height: 36,
105 decoration: BoxDecoration(
106 color: Theme.of(context).colorScheme.primary,
107 shape: BoxShape.circle,
108 ),
109 child: Center(
110 child: Text(
111 balance.asset.name
112 .substring(0, min(2, balance.asset.name.length)),
113 style: TextStyle(
114 fontSize: 20,
115 color: Theme.of(context).colorScheme.onPrimary,
116 ),
117 ),
118 ),
119 ),
120 ),
121 SizedBox(width: 12.0),
122 Expanded(
123 child: Column(
124 spacing: 4.0,
125 mainAxisAlignment: MainAxisAlignment.center,
126 crossAxisAlignment: CrossAxisAlignment.start,
127 children: [
128 Row(
129 spacing: 4,
130 children: [
131 Text(
132 title ?? balance.asset.fullName ?? balance.asset.name,
133 style: TextStyle(fontWeight: FontWeight.w500),
134 ),
135 if (trailingText != null)
136 Text(
137 trailingText!,
138 style: TextStyle(
139 color: Theme.of(context).colorScheme.onSurfaceVariant),
140 ),
141 ],
142 ),
143 Padding(
144 padding: const EdgeInsets.only(right: 4.0),
145 child: FittedBox(
146 fit: BoxFit.scaleDown,
147 alignment: Alignment.centerLeft,
148 child: Text(
149 "${showSecondary ? balance.secondAvailableBalance : balance.availableBalance} ${balance.formattedAssetTitle.safeSubString(0, 6)}",
150 maxLines: 1,
151 style: TextStyle(
152 color: Theme.of(context).colorScheme.onSurfaceVariant,
153 ),
154 ),
155 ),
156 ),
157 ],
158 ),
159 ),
160 ],
161 ),
162 ),
163 Text(
164 showSecondary
165 ? balance.fiatSecondAvailableBalance
166 : balance.fiatAvailableBalance,
167 style: TextStyle(
168 color: Theme.of(context).colorScheme.onSurface,
169 ),
170 ),
171 ],
172 ),
173 ),
174 ),
175 ),
176 ),
177 ),
178 );
179 }
180
181 String _getChainTitle() => walletTypeToDisplayName(wallet.type);
182 }