dev
dart 90 lines 2.56 KB
Raw
1 import 'package:cake_wallet/generated/i18n.dart';
2 import 'package:cw_core/wallet_type.dart';
3 import 'package:flutter/material.dart';
4
5 class ChainChipStrip extends StatelessWidget {
6 const ChainChipStrip({
7 super.key,
8 required this.walletTypes,
9 required this.selected,
10 required this.onSelected,
11 });
12
13 final List<WalletType> walletTypes;
14 final WalletType? selected;
15 final ValueChanged<WalletType?> onSelected;
16
17 @override
18 Widget build(BuildContext context) {
19 return Container(
20 padding: const EdgeInsets.only(bottom: 4),
21 height: 48,
22 child: ListView(
23 scrollDirection: Axis.horizontal,
24 padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
25 children: [
26 _ChainChip(
27 label: S.of(context).picker_chip_all,
28 isSelected: selected == null,
29 onTap: () => onSelected(null),
30 ),
31 for (final type in walletTypes)
32 _ChainChip(
33 label: walletTypeToString(type),
34 isSelected: selected == type,
35 onTap: () => onSelected(type),
36 ),
37 ],
38 ),
39 );
40 }
41 }
42
43 class _ChainChip extends StatelessWidget {
44 const _ChainChip({
45 required this.label,
46 required this.isSelected,
47 required this.onTap,
48 });
49
50 final String label;
51 final bool isSelected;
52 final VoidCallback onTap;
53
54 @override
55 Widget build(BuildContext context) {
56 final colors = Theme.of(context).colorScheme;
57 return Padding(
58 padding: const EdgeInsetsDirectional.only(end: 8),
59 child: MergeSemantics(
60 child: Semantics(
61 button: true,
62 selected: isSelected,
63 inMutuallyExclusiveGroup: true,
64 child: InkWell(
65 onTap: onTap,
66 borderRadius: BorderRadius.circular(80),
67 child: Container(
68 padding: const EdgeInsets.symmetric(horizontal: 10),
69 decoration: BoxDecoration(
70 color: isSelected ? colors.primary : colors.surfaceContainer,
71 borderRadius: BorderRadius.circular(20),
72 ),
73 child: Center(
74 child: Text(
75 label,
76 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
77 fontWeight: FontWeight.w500,
78 fontSize: isSelected ? 14 : 12,
79 letterSpacing: -0.07,
80 color: isSelected ? colors.onPrimary : colors.primary,
81 ),
82 ),
83 ),
84 ),
85 ),
86 ),
87 ),
88 );
89 }
90 }