| 1 | import "package:cake_wallet/exchange/trade_state.dart"; |
| 2 | import "package:cake_wallet/palette.dart"; |
| 3 | import "package:cake_wallet/utils/image_utill.dart"; |
| 4 | import "package:flutter/material.dart"; |
| 5 | import "package:cake_wallet/exchange/exchange_provider_description.dart"; |
| 6 | |
| 7 | class TradeRow extends StatelessWidget { |
| 8 | TradeRow({ |
| 9 | required this.provider, |
| 10 | required this.title, |
| 11 | required this.fromSymbol, |
| 12 | required this.toSymbol, |
| 13 | required this.createdAtFormattedDate, |
| 14 | this.onTap, |
| 15 | this.formattedAmount, |
| 16 | this.formattedReceiveAmount, |
| 17 | required this.swapState, |
| 18 | super.key, |
| 19 | }); |
| 20 | |
| 21 | final VoidCallback? onTap; |
| 22 | final ExchangeProviderDescription provider; |
| 23 | final String fromSymbol; |
| 24 | final String toSymbol; |
| 25 | final String title; |
| 26 | final String? createdAtFormattedDate; |
| 27 | final String? formattedAmount; |
| 28 | final String? formattedReceiveAmount; |
| 29 | final TradeState swapState; |
| 30 | |
| 31 | @override |
| 32 | Widget build(BuildContext context) { |
| 33 | return InkWell( |
| 34 | onTap: onTap, |
| 35 | child: Container( |
| 36 | padding: EdgeInsets.fromLTRB(24, 8, 24, 8), |
| 37 | color: Colors.transparent, |
| 38 | child: Row( |
| 39 | mainAxisSize: MainAxisSize.max, |
| 40 | crossAxisAlignment: CrossAxisAlignment.center, |
| 41 | children: [ |
| 42 | Stack( |
| 43 | clipBehavior: Clip.none, |
| 44 | children: [ |
| 45 | ClipRRect( |
| 46 | borderRadius: BorderRadius.circular(50), |
| 47 | child: |
| 48 | ImageUtil.getImageFromPath(imagePath: provider.image, height: 36, width: 36), |
| 49 | ), |
| 50 | Positioned( |
| 51 | right: 0, |
| 52 | bottom: 2, |
| 53 | child: Container( |
| 54 | height: 8, |
| 55 | width: 8, |
| 56 | padding: EdgeInsets.symmetric(horizontal: 8, vertical: 2), |
| 57 | decoration: BoxDecoration( |
| 58 | color: _statusColor(context, swapState), |
| 59 | borderRadius: BorderRadius.circular(12), |
| 60 | ), |
| 61 | ), |
| 62 | ), |
| 63 | ], |
| 64 | ), |
| 65 | SizedBox(width: 12), |
| 66 | Expanded( |
| 67 | child: Column( |
| 68 | mainAxisSize: MainAxisSize.min, |
| 69 | children: [ |
| 70 | Row( |
| 71 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 72 | children: <Widget>[ |
| 73 | Text( |
| 74 | title, |
| 75 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 76 | fontSize: 16, |
| 77 | fontWeight: FontWeight.w600, |
| 78 | color: Theme.of(context).colorScheme.primary), |
| 79 | ), |
| 80 | formattedAmount != null |
| 81 | ? Text( |
| 82 | "$formattedAmount $fromSymbol", |
| 83 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 84 | fontSize: 16, |
| 85 | fontWeight: FontWeight.w500, |
| 86 | color: Theme.of(context).colorScheme.onSurface, |
| 87 | ), |
| 88 | ) |
| 89 | : Container() |
| 90 | ], |
| 91 | ), |
| 92 | SizedBox(height: 5), |
| 93 | Row( |
| 94 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 95 | children: <Widget>[ |
| 96 | createdAtFormattedDate != null |
| 97 | ? Text( |
| 98 | createdAtFormattedDate!, |
| 99 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 100 | fontWeight: FontWeight.w500, |
| 101 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 102 | ), |
| 103 | ) |
| 104 | : Container(), |
| 105 | formattedReceiveAmount != null |
| 106 | ? Text( |
| 107 | "$formattedReceiveAmount $toSymbol", |
| 108 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 109 | fontWeight: FontWeight.w500, |
| 110 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 111 | ), |
| 112 | ) |
| 113 | : Container(), |
| 114 | ], |
| 115 | ) |
| 116 | ], |
| 117 | ), |
| 118 | ) |
| 119 | ], |
| 120 | ), |
| 121 | ), |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | Color _statusColor(BuildContext context, TradeState status) { |
| 126 | switch (status) { |
| 127 | case TradeState.complete: |
| 128 | case TradeState.completed: |
| 129 | case TradeState.finished: |
| 130 | case TradeState.success: |
| 131 | case TradeState.settled: |
| 132 | return PaletteDark.brightGreen; |
| 133 | case TradeState.failed: |
| 134 | case TradeState.expired: |
| 135 | case TradeState.notFound: |
| 136 | return Palette.darkRed; |
| 137 | default: |
| 138 | return const Color(0xffff6600); |
| 139 | } |
| 140 | } |
| 141 | } |