| 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 PillGrid extends StatelessWidget { |
| 7 | const PillGrid({ |
| 8 | super.key, |
| 9 | required this.items, |
| 10 | required this.selected, |
| 11 | required this.onTap, |
| 12 | required this.symbolResolver, |
| 13 | }); |
| 14 | |
| 15 | final List<CryptoCurrency> items; |
| 16 | final CryptoCurrency? selected; |
| 17 | final ValueChanged<CryptoCurrency> onTap; |
| 18 | final String Function(CryptoCurrency c) symbolResolver; |
| 19 | |
| 20 | @override |
| 21 | Widget build(BuildContext context) { |
| 22 | return LayoutBuilder( |
| 23 | builder: (context, constraints) { |
| 24 | const gap = 8.0; |
| 25 | final cardWidth = (constraints.maxWidth - gap) / 2; |
| 26 | return Wrap( |
| 27 | spacing: gap, |
| 28 | runSpacing: gap, |
| 29 | children: [ |
| 30 | for (final item in items) |
| 31 | SizedBox( |
| 32 | width: cardWidth, |
| 33 | child: _PillCard( |
| 34 | currency: item, |
| 35 | isSelected: selected != null && selected == item, |
| 36 | label: symbolResolver(item), |
| 37 | onTap: () => onTap(item), |
| 38 | ), |
| 39 | ), |
| 40 | ], |
| 41 | ); |
| 42 | }, |
| 43 | ); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | class _PillCard extends StatelessWidget { |
| 48 | const _PillCard({ |
| 49 | required this.currency, |
| 50 | required this.isSelected, |
| 51 | required this.label, |
| 52 | required this.onTap, |
| 53 | }); |
| 54 | |
| 55 | final CryptoCurrency currency; |
| 56 | final bool isSelected; |
| 57 | final String label; |
| 58 | final VoidCallback onTap; |
| 59 | |
| 60 | @override |
| 61 | Widget build(BuildContext context) { |
| 62 | final colors = Theme.of(context).colorScheme; |
| 63 | return InkWell( |
| 64 | onTap: onTap, |
| 65 | borderRadius: BorderRadius.circular(80), |
| 66 | child: Container( |
| 67 | padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10), |
| 68 | decoration: BoxDecoration( |
| 69 | color: colors.surfaceContainer, |
| 70 | borderRadius: BorderRadius.circular(80), |
| 71 | border: isSelected ? Border.all(color: colors.primary, width: 1.5) : null, |
| 72 | ), |
| 73 | child: Row( |
| 74 | children: [ |
| 75 | TokenImageWidget( |
| 76 | imageUrl: currency.iconPath ?? '', |
| 77 | size: 24, |
| 78 | ), |
| 79 | const SizedBox(width: 8), |
| 80 | Expanded( |
| 81 | child: Text( |
| 82 | label, |
| 83 | overflow: TextOverflow.ellipsis, |
| 84 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 85 | fontWeight: FontWeight.w600, |
| 86 | ), |
| 87 | ), |
| 88 | ), |
| 89 | Icon( |
| 90 | Icons.chevron_right, |
| 91 | size: 18, |
| 92 | color: colors.onSurfaceVariant, |
| 93 | ), |
| 94 | ], |
| 95 | ), |
| 96 | ), |
| 97 | ); |
| 98 | } |
| 99 | } |