| 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 | |
| 6 | class OrderRow extends StatelessWidget { |
| 7 | const OrderRow({ |
| 8 | Key? key, |
| 9 | required this.providerTitle, |
| 10 | required this.providerIconPath, |
| 11 | required this.from, |
| 12 | required this.to, |
| 13 | required this.createdAtFormattedDate, |
| 14 | this.state, |
| 15 | this.onTap, |
| 16 | this.formattedAmount, |
| 17 | this.formattedReceiveAmount, |
| 18 | }) : super(key: key); |
| 19 | |
| 20 | final VoidCallback? onTap; |
| 21 | |
| 22 | final String providerTitle; |
| 23 | final String providerIconPath; |
| 24 | |
| 25 | final String from; |
| 26 | final String to; |
| 27 | final String? createdAtFormattedDate; |
| 28 | final String? formattedAmount; |
| 29 | final String? formattedReceiveAmount; |
| 30 | final TradeState? state; |
| 31 | |
| 32 | @override |
| 33 | Widget build(BuildContext context) { |
| 34 | return InkWell( |
| 35 | onTap: onTap, |
| 36 | child: Container( |
| 37 | padding: const EdgeInsets.fromLTRB(24, 8, 24, 8), |
| 38 | color: Colors.transparent, |
| 39 | child: Row( |
| 40 | crossAxisAlignment: CrossAxisAlignment.center, |
| 41 | children: [ |
| 42 | Stack( |
| 43 | clipBehavior: Clip.none, |
| 44 | children: [ |
| 45 | _ProviderIcon(path: providerIconPath, title: providerTitle), |
| 46 | if (state != null) |
| 47 | Positioned( |
| 48 | right: 0, |
| 49 | bottom: 2, |
| 50 | child: Container( |
| 51 | height: 8, |
| 52 | width: 8, |
| 53 | decoration: BoxDecoration( |
| 54 | color: _statusColor(context, state!), |
| 55 | borderRadius: BorderRadius.circular(12), |
| 56 | ), |
| 57 | ), |
| 58 | ), |
| 59 | ], |
| 60 | ), |
| 61 | const SizedBox(width: 12), |
| 62 | Expanded( |
| 63 | child: Column( |
| 64 | mainAxisSize: MainAxisSize.min, |
| 65 | children: [ |
| 66 | Row( |
| 67 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 68 | children: <Widget>[ |
| 69 | Text( |
| 70 | '$from → $to', |
| 71 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 72 | fontSize: 16, |
| 73 | fontWeight: FontWeight.w600, |
| 74 | color: Theme.of(context).colorScheme.primary, |
| 75 | ), |
| 76 | ), |
| 77 | if (formattedAmount != null) |
| 78 | Text( |
| 79 | formattedAmount!, |
| 80 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 81 | fontSize: 16, |
| 82 | fontWeight: FontWeight.w500, |
| 83 | color: Theme.of(context).colorScheme.onSurface, |
| 84 | ), |
| 85 | ), |
| 86 | ], |
| 87 | ), |
| 88 | const SizedBox(height: 5), |
| 89 | Row( |
| 90 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 91 | children: <Widget>[ |
| 92 | if (createdAtFormattedDate != null) |
| 93 | Text( |
| 94 | createdAtFormattedDate!, |
| 95 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 96 | fontWeight: FontWeight.w500, |
| 97 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 98 | ), |
| 99 | ), |
| 100 | if (formattedReceiveAmount != null) |
| 101 | Text( |
| 102 | formattedReceiveAmount!, |
| 103 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 104 | fontWeight: FontWeight.w500, |
| 105 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 106 | ), |
| 107 | ), |
| 108 | ], |
| 109 | ) |
| 110 | ], |
| 111 | ), |
| 112 | ) |
| 113 | ], |
| 114 | ), |
| 115 | ), |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | Color _statusColor(BuildContext context, TradeState status) { |
| 120 | switch (status) { |
| 121 | case TradeState.complete: |
| 122 | case TradeState.completed: |
| 123 | case TradeState.finished: |
| 124 | case TradeState.success: |
| 125 | case TradeState.settled: |
| 126 | return PaletteDark.brightGreen; |
| 127 | case TradeState.failed: |
| 128 | case TradeState.expired: |
| 129 | case TradeState.notFound: |
| 130 | return Palette.darkRed; |
| 131 | default: |
| 132 | return const Color(0xffff6600); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | class _ProviderIcon extends StatelessWidget { |
| 138 | const _ProviderIcon({required this.path, required this.title}); |
| 139 | |
| 140 | final String path; |
| 141 | final String title; |
| 142 | |
| 143 | @override |
| 144 | Widget build(BuildContext context) { |
| 145 | if (path.isNotEmpty) { |
| 146 | return ClipRRect( |
| 147 | borderRadius: BorderRadius.circular(50), |
| 148 | child: ImageUtil.getImageFromPath(imagePath: path, height: 36, width: 36), |
| 149 | ); |
| 150 | } |
| 151 | return Container( |
| 152 | height: 36, |
| 153 | width: 36, |
| 154 | decoration: BoxDecoration( |
| 155 | borderRadius: BorderRadius.circular(50), |
| 156 | color: Theme.of(context).colorScheme.surfaceVariant, |
| 157 | ), |
| 158 | alignment: Alignment.center, |
| 159 | child: Text( |
| 160 | title.isNotEmpty ? title.characters.first.toUpperCase() : '?', |
| 161 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 162 | fontWeight: FontWeight.w700, |
| 163 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 164 | ), |
| 165 | ), |
| 166 | ); |
| 167 | } |
| 168 | } |