dev
dart 155 lines 5.45 KB
Raw
1 import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
2 import 'package:cw_core/currency_for_wallet_type.dart';
3 import 'package:flutter/material.dart';
4 import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
5
6 class GroupedWalletExpansionTile extends StatelessWidget {
7 GroupedWalletExpansionTile({
8 required this.title,
9 required this.isSelected,
10 this.childWallets = const [],
11 this.onTitleTapped,
12 this.onChildItemTapped = _defaultVoidCallback,
13 this.onExpansionChanged,
14 this.leadingWidget,
15 this.trailingWidget,
16 this.childTrailingWidget,
17 this.decoration,
18 this.color,
19 this.textColor,
20 this.arrowColor,
21 this.borderRadius,
22 this.margin,
23 this.tileKey,
24 this.isCurrentlySelectedWallet = false,
25 this.shouldShowCurrentWalletPointer = false,
26 }) : super(key: tileKey);
27
28 final Key? tileKey;
29 final bool isSelected;
30 final bool isCurrentlySelectedWallet;
31 final bool shouldShowCurrentWalletPointer;
32
33 final VoidCallback? onTitleTapped;
34 final void Function(WalletListItem item) onChildItemTapped;
35 final void Function(bool)? onExpansionChanged;
36
37 final String title;
38 final Widget? leadingWidget;
39 final Widget? trailingWidget;
40 final Widget Function(WalletListItem)? childTrailingWidget;
41
42 final List<WalletListItem> childWallets;
43
44 final Color? color;
45 final Color? textColor;
46 final Color? arrowColor;
47 final EdgeInsets? margin;
48 final Decoration? decoration;
49 final BorderRadius? borderRadius;
50
51 static void _defaultVoidCallback(WalletListItem ITEM) {}
52
53 @override
54 Widget build(BuildContext context) {
55 final backgroundColor = color ??
56 (isSelected
57 ? Theme.of(context).colorScheme.primary
58 : Theme.of(context).colorScheme.surfaceContainer);
59 final effectiveTextColor = textColor ??
60 (isSelected
61 ? Theme.of(context).colorScheme.onPrimary
62 : Theme.of(context).colorScheme.onSurface);
63
64 final effectiveArrowColor = arrowColor ??
65 (isSelected
66 ? Theme.of(context).colorScheme.onPrimary
67 : Theme.of(context).colorScheme.onSurfaceVariant);
68 return Padding(
69 padding: EdgeInsets.symmetric(vertical: 6),
70 child: ExpansionTile(
71 shape: RoundedSuperellipseBorder(borderRadius: BorderRadius.circular(18)),
72 collapsedShape: RoundedSuperellipseBorder(borderRadius: BorderRadius.circular(18)),
73 collapsedBackgroundColor: backgroundColor,
74 backgroundColor: backgroundColor,
75 onExpansionChanged: onExpansionChanged,
76 initiallyExpanded: shouldShowCurrentWalletPointer
77 ? childWallets.any((element) => element.isCurrent)
78 : false,
79 key: tileKey,
80 tilePadding:
81 EdgeInsets.symmetric(vertical: 1, horizontal: !isCurrentlySelectedWallet ? 16 : 0),
82 iconColor: effectiveArrowColor,
83 collapsedIconColor: effectiveArrowColor,
84 leading: (childWallets.isEmpty && onTitleTapped != null && leadingWidget != null)
85 ? GestureDetector(
86 behavior: HitTestBehavior.opaque,
87 onTap: onTitleTapped,
88 child: leadingWidget,
89 )
90 : leadingWidget,
91 trailing: trailingWidget ?? (childWallets.isEmpty ? SizedBox.shrink() : null),
92 title: GestureDetector(
93 onTap: onTitleTapped,
94 child: Text(
95 title,
96 style: Theme.of(context).textTheme.bodyMedium!.copyWith(
97 fontSize: 18,
98 fontWeight: FontWeight.w500,
99 color: effectiveTextColor,
100 ),
101 textAlign: TextAlign.left,
102 ),
103 ),
104 children: childWallets.map(
105 (item) {
106 final currentColor = item.isCurrent
107 ? Theme.of(context).colorScheme.primary
108 : Theme.of(context).colorScheme.surface;
109 return ListTile(
110 contentPadding: EdgeInsets.zero,
111 key: ValueKey(item.name),
112 trailing: childTrailingWidget?.call(item),
113 onTap: () => onChildItemTapped(item),
114 leading: SizedBox(
115 width: 64,
116 child: Row(
117 children: [
118 item.isCurrent && shouldShowCurrentWalletPointer
119 ? Container(
120 height: 35,
121 width: 6,
122 decoration: BoxDecoration(
123 borderRadius: BorderRadius.only(
124 topRight: Radius.circular(16),
125 bottomRight: Radius.circular(16),
126 ),
127 color: currentColor,
128 ),
129 )
130 : SizedBox(width: 7),
131 SizedBox(width: 24),
132 CakeImageWidget(
133 imageUrl: getCryptoCurrencyIconForWalletListItem(item.type),
134 width: 32,
135 height: 32,
136 ),
137 ],
138 ),
139 ),
140 title: Text(
141 item.name,
142 maxLines: 2,
143 style: Theme.of(context).textTheme.bodyMedium!.copyWith(
144 fontSize: 18,
145 fontWeight: FontWeight.w500,
146 color: effectiveTextColor,
147 ),
148 ),
149 );
150 },
151 ).toList(),
152 ),
153 );
154 }
155 }