| 1 | import 'package:cake_wallet/new-ui/widgets/coins_page/token_image_widget.dart'; |
| 2 | import 'package:cake_wallet/src/widgets/cake_image_widget.dart'; |
| 3 | import 'package:cw_core/crypto_currency.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | |
| 6 | class CurrencyPickerRow extends StatelessWidget { |
| 7 | const CurrencyPickerRow({ |
| 8 | super.key, |
| 9 | required this.currency, |
| 10 | required this.isSelected, |
| 11 | required this.trailing, |
| 12 | required this.onTap, |
| 13 | this.chainPillLabel, |
| 14 | this.chainBadgePath, |
| 15 | }); |
| 16 | |
| 17 | final CryptoCurrency currency; |
| 18 | final bool isSelected; |
| 19 | final Widget trailing; |
| 20 | final VoidCallback onTap; |
| 21 | final String? chainPillLabel; |
| 22 | final String? chainBadgePath; |
| 23 | |
| 24 | @override |
| 25 | Widget build(BuildContext context) { |
| 26 | final colors = Theme.of(context).colorScheme; |
| 27 | return MergeSemantics( |
| 28 | child: Semantics( |
| 29 | button: true, |
| 30 | selected: isSelected, |
| 31 | child: InkWell( |
| 32 | onTap: onTap, |
| 33 | child: Padding( |
| 34 | padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12), |
| 35 | child: Row( |
| 36 | children: [ |
| 37 | ExcludeSemantics( |
| 38 | child: _IconWithBadge(currency: currency, badgePath: chainBadgePath), |
| 39 | ), |
| 40 | const SizedBox(width: 12), |
| 41 | Expanded( |
| 42 | child: Row( |
| 43 | children: [ |
| 44 | Flexible( |
| 45 | child: Text( |
| 46 | currency.fullName ?? currency.title, |
| 47 | overflow: TextOverflow.ellipsis, |
| 48 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 49 | fontWeight: FontWeight.w500, |
| 50 | ), |
| 51 | ), |
| 52 | ), |
| 53 | if (chainPillLabel != null) ...[ |
| 54 | const SizedBox(width: 8), |
| 55 | Container( |
| 56 | padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), |
| 57 | decoration: BoxDecoration( |
| 58 | color: colors.surfaceContainerHigh, |
| 59 | borderRadius: BorderRadius.circular(10), |
| 60 | ), |
| 61 | child: Text( |
| 62 | chainPillLabel!, |
| 63 | style: Theme.of(context).textTheme.bodySmall?.copyWith( |
| 64 | fontWeight: FontWeight.w500, |
| 65 | color: colors.onSecondaryContainer, |
| 66 | ), |
| 67 | ), |
| 68 | ), |
| 69 | ], |
| 70 | ], |
| 71 | ), |
| 72 | ), |
| 73 | const SizedBox(width: 8), |
| 74 | trailing, |
| 75 | const SizedBox(width: 8), |
| 76 | ExcludeSemantics( |
| 77 | child: Icon( |
| 78 | Icons.chevron_right, |
| 79 | size: 20, |
| 80 | color: isSelected ? colors.primary : colors.onSurfaceVariant, |
| 81 | ), |
| 82 | ), |
| 83 | ], |
| 84 | ), |
| 85 | ), |
| 86 | ), |
| 87 | ), |
| 88 | ); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | class _IconWithBadge extends StatelessWidget { |
| 93 | const _IconWithBadge({required this.currency, required this.badgePath}); |
| 94 | |
| 95 | final CryptoCurrency currency; |
| 96 | final String? badgePath; |
| 97 | |
| 98 | @override |
| 99 | Widget build(BuildContext context) { |
| 100 | final icon = TokenImageWidget( |
| 101 | imageUrl: currency.iconPath ?? '', |
| 102 | size: 32, |
| 103 | errorWidget: Container( |
| 104 | width: 32, |
| 105 | height: 32, |
| 106 | child: Center( |
| 107 | child: Text( |
| 108 | currency.title.length >= 2 ? currency.title.substring(0, 2) : currency.title, |
| 109 | ), |
| 110 | ), |
| 111 | ), |
| 112 | ); |
| 113 | if (badgePath == null) return icon; |
| 114 | return SizedBox( |
| 115 | width: 36, |
| 116 | height: 36, |
| 117 | child: Stack( |
| 118 | clipBehavior: Clip.none, |
| 119 | children: [ |
| 120 | icon, |
| 121 | Positioned( |
| 122 | right: -2, |
| 123 | bottom: -2, |
| 124 | child: Container( |
| 125 | width: 18, |
| 126 | height: 18, |
| 127 | decoration: BoxDecoration( |
| 128 | borderRadius: BorderRadius.circular(6), |
| 129 | border: Border.all( |
| 130 | color: Theme.of(context).colorScheme.surfaceContainerHigh, |
| 131 | width: 2, |
| 132 | ), |
| 133 | color: Theme.of(context).colorScheme.onSurface, |
| 134 | ), |
| 135 | padding: const EdgeInsets.all(2), |
| 136 | child: CakeImageWidget( |
| 137 | imageUrl: badgePath, |
| 138 | color: Theme.of(context).colorScheme.surface, |
| 139 | width: 13, |
| 140 | height: 13, |
| 141 | fit: BoxFit.cover, |
| 142 | ), |
| 143 | ), |
| 144 | ), |
| 145 | ], |
| 146 | ), |
| 147 | ); |
| 148 | } |
| 149 | } |