| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter_slidable/flutter_slidable.dart'; |
| 3 | import 'package:cake_wallet/generated/i18n.dart'; |
| 4 | |
| 5 | class AccountTile extends StatelessWidget { |
| 6 | AccountTile( |
| 7 | {required this.isCurrent, |
| 8 | required this.accountName, |
| 9 | this.accountBalance, |
| 10 | required this.currency, |
| 11 | required this.onTap, |
| 12 | required this.onEdit}); |
| 13 | |
| 14 | final bool isCurrent; |
| 15 | final String accountName; |
| 16 | final String? accountBalance; |
| 17 | final String currency; |
| 18 | final Function() onTap; |
| 19 | final Function() onEdit; |
| 20 | |
| 21 | @override |
| 22 | Widget build(BuildContext context) { |
| 23 | final color = isCurrent |
| 24 | ? Theme.of(context).colorScheme.primaryContainer |
| 25 | : Theme.of(context).colorScheme.surfaceContainerHighest; |
| 26 | final textColor = isCurrent |
| 27 | ? Theme.of(context).colorScheme.onPrimaryContainer |
| 28 | : Theme.of(context).colorScheme.onSurfaceVariant; |
| 29 | |
| 30 | final Widget cell = GestureDetector( |
| 31 | onTap: onTap, |
| 32 | child: Container( |
| 33 | height: 77, |
| 34 | width: double.infinity, |
| 35 | padding: EdgeInsets.only(left: 24, right: 24), |
| 36 | color: color, |
| 37 | child: Wrap( |
| 38 | direction: Axis.horizontal, |
| 39 | alignment: WrapAlignment.spaceBetween, |
| 40 | runAlignment: WrapAlignment.center, |
| 41 | crossAxisAlignment: WrapCrossAlignment.center, |
| 42 | children: [ |
| 43 | Container( |
| 44 | child: Text( |
| 45 | accountName, |
| 46 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 47 | fontSize: 18, |
| 48 | fontWeight: FontWeight.w600, |
| 49 | color: textColor, |
| 50 | decoration: TextDecoration.none, |
| 51 | ), |
| 52 | ), |
| 53 | ), |
| 54 | if (accountBalance != null) |
| 55 | Container( |
| 56 | child: Text( |
| 57 | '${accountBalance.toString()} $currency', |
| 58 | textAlign: TextAlign.end, |
| 59 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 60 | fontSize: 15, |
| 61 | fontWeight: FontWeight.w600, |
| 62 | color: Theme.of(context).textTheme.headlineMedium!.color!, |
| 63 | decoration: TextDecoration.none, |
| 64 | ), |
| 65 | ), |
| 66 | ), |
| 67 | ], |
| 68 | ), |
| 69 | ), |
| 70 | ); |
| 71 | |
| 72 | // return cell; |
| 73 | return Slidable(key: Key(accountName), child: cell, endActionPane: _actionPane(context)); |
| 74 | } |
| 75 | |
| 76 | ActionPane _actionPane(BuildContext context) => ActionPane( |
| 77 | motion: const ScrollMotion(), |
| 78 | extentRatio: 0.3, |
| 79 | children: [ |
| 80 | SlidableAction( |
| 81 | onPressed: (_) => onEdit.call(), |
| 82 | backgroundColor: Theme.of(context).colorScheme.primaryContainer, |
| 83 | foregroundColor: Theme.of(context).colorScheme.onPrimaryContainer, |
| 84 | icon: Icons.edit, |
| 85 | label: S.of(context).edit, |
| 86 | ), |
| 87 | ], |
| 88 | ); |
| 89 | } |