| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/new-ui/widgets/currency_picker/currency_picker_args.dart'; |
| 3 | import 'package:cake_wallet/new-ui/widgets/currency_picker/currency_picker_list_container.dart'; |
| 4 | import 'package:cake_wallet/new-ui/widgets/receive_page/receive_top_bar.dart'; |
| 5 | import 'package:cake_wallet/src/widgets/cake_image_widget.dart'; |
| 6 | import 'package:cw_core/crypto_currency.dart'; |
| 7 | import 'package:cw_core/currency_for_wallet_type.dart'; |
| 8 | import 'package:cw_core/wallet_type.dart'; |
| 9 | import 'package:flutter/material.dart'; |
| 10 | |
| 11 | class SelectNetworkPage extends StatelessWidget { |
| 12 | const SelectNetworkPage({ |
| 13 | super.key, |
| 14 | required this.assetTitle, |
| 15 | required this.assetFullName, |
| 16 | required this.assetIconPath, |
| 17 | required this.variants, |
| 18 | required this.onSelected, |
| 19 | }); |
| 20 | |
| 21 | final String assetTitle; |
| 22 | final String? assetFullName; |
| 23 | final String? assetIconPath; |
| 24 | final List<CryptoCurrency> variants; |
| 25 | final ValueChanged<CryptoCurrency> onSelected; |
| 26 | |
| 27 | @override |
| 28 | Widget build(BuildContext context) { |
| 29 | final colors = Theme.of(context).colorScheme; |
| 30 | return Scaffold( |
| 31 | backgroundColor: colors.surface, |
| 32 | body: SafeArea( |
| 33 | child: Column( |
| 34 | children: [ |
| 35 | ModalTopBar( |
| 36 | title: S.of(context).select_network_title, |
| 37 | leadingIcon: const Icon(Icons.arrow_back), |
| 38 | leadingSemanticLabel: S.of(context).seed_alert_back, |
| 39 | onLeadingPressed: () => Navigator.of(context).maybePop(), |
| 40 | ), |
| 41 | const SizedBox(height: 24), |
| 42 | // Illustration of the asset named by the title below it. |
| 43 | ExcludeSemantics( |
| 44 | child: CakeImageWidget( |
| 45 | imageUrl: assetIconPath, |
| 46 | width: 75, |
| 47 | height: 75, |
| 48 | fit: BoxFit.cover, |
| 49 | ), |
| 50 | ), |
| 51 | const SizedBox(height: 12), |
| 52 | Text( |
| 53 | assetTitle, |
| 54 | style: Theme.of(context).textTheme.titleLarge?.copyWith( |
| 55 | fontSize: 20, |
| 56 | fontWeight: FontWeight.w600, |
| 57 | ), |
| 58 | ), |
| 59 | const SizedBox(height: 12), |
| 60 | Padding( |
| 61 | padding: const EdgeInsets.symmetric(horizontal: 32), |
| 62 | child: Text( |
| 63 | S.of(context).select_network_subtitle, |
| 64 | textAlign: TextAlign.center, |
| 65 | style: Theme.of(context) |
| 66 | .textTheme |
| 67 | .bodyMedium |
| 68 | ?.copyWith(color: colors.onSurfaceVariant), |
| 69 | ), |
| 70 | ), |
| 71 | const SizedBox(height: 24), |
| 72 | Expanded( |
| 73 | child: ListView( |
| 74 | padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), |
| 75 | children: [ |
| 76 | CurrencyPickerListContainer( |
| 77 | rows: [ |
| 78 | for (final variant in variants) |
| 79 | _NetworkRow( |
| 80 | variant: variant, |
| 81 | onTap: () { |
| 82 | final nav = Navigator.of(context); |
| 83 | onSelected(variant); |
| 84 | if (nav.canPop()) nav.pop(); |
| 85 | if (nav.canPop()) nav.pop(); |
| 86 | }, |
| 87 | ), |
| 88 | ], |
| 89 | ), |
| 90 | ], |
| 91 | ), |
| 92 | ), |
| 93 | ], |
| 94 | ), |
| 95 | ), |
| 96 | ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | class _NetworkRow extends StatelessWidget { |
| 101 | const _NetworkRow({required this.variant, required this.onTap}); |
| 102 | |
| 103 | final CryptoCurrency variant; |
| 104 | final VoidCallback onTap; |
| 105 | |
| 106 | @override |
| 107 | Widget build(BuildContext context) { |
| 108 | final colors = Theme.of(context).colorScheme; |
| 109 | final wt = cryptoCurrencyOrTokenToWalletType(variant); |
| 110 | final networkIconPath = |
| 111 | wt != null ? getCryptoCurrencyIconForWalletListItem(wt) : variant.iconPath; |
| 112 | final networkName = chainNameForCurrency(variant); |
| 113 | return MergeSemantics( |
| 114 | child: Semantics( |
| 115 | button: true, |
| 116 | child: InkWell( |
| 117 | onTap: onTap, |
| 118 | child: Padding( |
| 119 | padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14), |
| 120 | child: Row( |
| 121 | children: [ |
| 122 | ExcludeSemantics( |
| 123 | child: CakeImageWidget( |
| 124 | imageUrl: networkIconPath, |
| 125 | width: 28, |
| 126 | height: 28, |
| 127 | fit: BoxFit.cover, |
| 128 | ), |
| 129 | ), |
| 130 | const SizedBox(width: 12), |
| 131 | Expanded( |
| 132 | child: Text( |
| 133 | networkName, |
| 134 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 135 | fontWeight: FontWeight.w500, |
| 136 | ), |
| 137 | ), |
| 138 | ), |
| 139 | ExcludeSemantics( |
| 140 | child: Icon( |
| 141 | Icons.chevron_right, |
| 142 | size: 20, |
| 143 | color: colors.onSurfaceVariant, |
| 144 | ), |
| 145 | ), |
| 146 | ], |
| 147 | ), |
| 148 | ), |
| 149 | ), |
| 150 | ), |
| 151 | ); |
| 152 | } |
| 153 | } |