dev
dart 120 lines 3.97 KB
Raw
1 import 'package:cake_wallet/generated/i18n.dart';
2 import 'package:cake_wallet/new-ui/widgets/modern_button.dart';
3 import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
4 import 'package:cw_core/wallet_info.dart';
5 import 'package:flutter/material.dart';
6 import 'package:flutter/services.dart';
7 import 'package:flutter_svg/flutter_svg.dart';
8
9 class WalletInfoBar extends StatelessWidget {
10 const WalletInfoBar(
11 {super.key,
12 required this.lightningMode,
13 required this.name,
14 required this.hardwareWalletType,
15 required this.onCustomizeButtonTap,
16 required this.hasCustomize});
17
18 final bool lightningMode;
19 final String name;
20 final HardwareWalletType? hardwareWalletType;
21 final bool hasCustomize;
22 final VoidCallback onCustomizeButtonTap;
23
24 void _openAccountCustomizer() {
25 if (hasCustomize) {
26 onCustomizeButtonTap();
27 HapticFeedback.mediumImpact();
28 }
29 }
30
31 @override
32 Widget build(BuildContext context) {
33 // The row, the hardware-wallet glyph and the inner accounts button are one
34 // control for a screen reader: a single labeled node opening the customizer.
35 final semanticsLabel =
36 hardwareWalletType == null ? name : "$name, ${S.of(context).hardware_wallet}";
37
38 final row = GestureDetector(
39 onTap: _openAccountCustomizer,
40 child: Row(
41 mainAxisSize: MainAxisSize.min,
42 mainAxisAlignment: MainAxisAlignment.center,
43 children: [
44 AnimatedSwitcher(
45 duration: Duration(milliseconds: 150),
46 transitionBuilder: (child, animation) {
47 return SizeTransition(
48 axis: Axis.horizontal,
49 sizeFactor: animation,
50 child: FadeTransition(opacity: animation, child: child),
51 );
52 },
53 child: hardwareWalletIcon == null
54 ? const SizedBox.shrink(key: ValueKey("empty"))
55 : Padding(
56 padding: const EdgeInsets.only(right: 8),
57 child: CakeImageWidget(
58 imageUrl: hardwareWalletIcon!,
59 key: ValueKey("hardware_wallet_icon"),
60 width: 24,
61 height: 24,
62 colorFilter: ColorFilter.mode(
63 Theme.of(context).colorScheme.onSurfaceVariant,
64 BlendMode.srcIn,
65 ),
66 ),
67 ),
68 ),
69 Text(
70 name,
71 style: Theme.of(context)
72 .textTheme
73 .titleLarge
74 ?.copyWith(color: Theme.of(context).colorScheme.onSurface),
75 ),
76 if (hasCustomize) ...[
77 SizedBox(width: 8),
78 ModernButton.svg(
79 size: 24,
80 onPressed: _openAccountCustomizer,
81 svgPath: "assets/new-ui/icon-accounts.svg",
82 semanticLabel: S.of(context).wallet_accounts,
83 )
84 ]
85 ],
86 ),
87 );
88
89 if (!hasCustomize) {
90 return Semantics(label: semanticsLabel, child: ExcludeSemantics(child: row));
91 }
92
93 return Semantics(
94 button: true,
95 label: semanticsLabel,
96 hint: S.of(context).wallet_accounts,
97 onTap: _openAccountCustomizer,
98 child: ExcludeSemantics(child: row),
99 );
100 }
101
102 String? get hardwareWalletIcon {
103 switch (hardwareWalletType) {
104 case null:
105 return null;
106 case HardwareWalletType.bitbox:
107 return "assets/new-ui/hardware_wallets/device_bitbox.svg";
108 case HardwareWalletType.ledger:
109 return "assets/new-ui/hardware_wallets/device_ledger_nano_x.svg";
110 case HardwareWalletType.trezor:
111 return "assets/new-ui/hardware_wallets/device_trezor_safe_5.svg";
112 case HardwareWalletType.cupcake:
113 return "assets/images/cupcake.svg";
114 case HardwareWalletType.coldcard:
115 case HardwareWalletType.seedsigner:
116 case HardwareWalletType.keystone:
117 return "assets/images/hardware_wallet/device_qr.svg";
118 }
119 }
120 }