| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:cw_core/transaction_direction.dart'; |
| 3 | import 'package:flutter_svg/svg.dart'; |
| 4 | |
| 5 | class TransactionRow extends StatelessWidget { |
| 6 | TransactionRow({ |
| 7 | required this.direction, |
| 8 | required this.formattedDate, |
| 9 | required this.formattedAmount, |
| 10 | required this.formattedFiatAmount, |
| 11 | required this.tags, |
| 12 | required this.title, |
| 13 | required this.onTap, |
| 14 | this.isShield = false, |
| 15 | super.key, |
| 16 | }); |
| 17 | |
| 18 | final VoidCallback onTap; |
| 19 | final TransactionDirection direction; |
| 20 | final String formattedDate; |
| 21 | final String formattedAmount; |
| 22 | final String formattedFiatAmount; |
| 23 | final String title; |
| 24 | final List<String> tags; |
| 25 | final bool isShield; |
| 26 | |
| 27 | @override |
| 28 | Widget build(BuildContext context) { |
| 29 | return InkWell( |
| 30 | onTap: onTap, |
| 31 | child: Container( |
| 32 | padding: EdgeInsets.fromLTRB(24, 8, 24, 8), |
| 33 | color: Colors.transparent, |
| 34 | child: Row( |
| 35 | mainAxisSize: MainAxisSize.max, |
| 36 | crossAxisAlignment: CrossAxisAlignment.center, |
| 37 | children: [ |
| 38 | Container( |
| 39 | height: 36, |
| 40 | width: 36, |
| 41 | decoration: BoxDecoration( |
| 42 | shape: BoxShape.circle, |
| 43 | color: Theme.of(context).colorScheme.surfaceContainerHighest, |
| 44 | ), |
| 45 | child: (isShield) |
| 46 | ? Padding( |
| 47 | padding: const EdgeInsets.all(8.0), |
| 48 | child: SvgPicture.asset('assets/images/tx_shield.svg'), |
| 49 | ) |
| 50 | : Image.asset(direction == TransactionDirection.incoming |
| 51 | ? 'assets/images/down_arrow.png' |
| 52 | : 'assets/images/up_arrow.png'), |
| 53 | ), |
| 54 | SizedBox(width: 12), |
| 55 | Expanded( |
| 56 | child: Column( |
| 57 | mainAxisSize: MainAxisSize.min, |
| 58 | children: [ |
| 59 | Row( |
| 60 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 61 | children: <Widget>[ |
| 62 | Expanded( |
| 63 | child: Row( |
| 64 | children: [ |
| 65 | Flexible( |
| 66 | child: Text( |
| 67 | title, |
| 68 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 69 | fontWeight: FontWeight.w600, |
| 70 | overflow: TextOverflow.fade, |
| 71 | ), |
| 72 | ), |
| 73 | ), |
| 74 | ...tags |
| 75 | .map((tag) => Row(children: [SizedBox(width: 8), TxTag(tag: tag)])), |
| 76 | ], |
| 77 | ), |
| 78 | ), |
| 79 | Text( |
| 80 | formattedAmount, |
| 81 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 82 | fontWeight: FontWeight.w600, |
| 83 | ), |
| 84 | ) |
| 85 | ], |
| 86 | ), |
| 87 | SizedBox(height: 5), |
| 88 | Row( |
| 89 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 90 | children: <Widget>[ |
| 91 | Text( |
| 92 | formattedDate, |
| 93 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 94 | fontWeight: FontWeight.w500, |
| 95 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 96 | ), |
| 97 | ), |
| 98 | Text( |
| 99 | formattedFiatAmount, |
| 100 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 101 | fontWeight: FontWeight.w500, |
| 102 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 103 | ), |
| 104 | ) |
| 105 | ], |
| 106 | ), |
| 107 | ], |
| 108 | ), |
| 109 | ) |
| 110 | ], |
| 111 | ), |
| 112 | ), |
| 113 | ); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // A tag to add context to a transaction |
| 118 | // example use: differ silent payments from regular txs |
| 119 | class TxTag extends StatelessWidget { |
| 120 | TxTag({required this.tag}); |
| 121 | |
| 122 | final String tag; |
| 123 | |
| 124 | @override |
| 125 | Widget build(BuildContext context) { |
| 126 | return Container( |
| 127 | height: 17, |
| 128 | padding: EdgeInsets.only(left: 6, right: 6), |
| 129 | decoration: BoxDecoration( |
| 130 | borderRadius: BorderRadius.all(Radius.circular(8.5)), |
| 131 | color: Theme.of(context).colorScheme.surfaceContainerHighest, |
| 132 | ), |
| 133 | alignment: Alignment.center, |
| 134 | child: Text( |
| 135 | tag.toLowerCase(), |
| 136 | style: Theme.of(context).textTheme.bodySmall?.copyWith( |
| 137 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 138 | fontSize: 9, |
| 139 | fontWeight: FontWeight.w600, |
| 140 | ), |
| 141 | ), |
| 142 | ); |
| 143 | } |
| 144 | } |