| 1 | import 'package:auto_size_text/auto_size_text.dart'; |
| 2 | import 'package:cake_wallet/entities/service_status.dart'; |
| 3 | import 'package:cake_wallet/themes/core/custom_theme_colors.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:intl/intl.dart'; |
| 6 | |
| 7 | class ServiceStatusTile extends StatelessWidget { |
| 8 | final ServiceStatus status; |
| 9 | |
| 10 | const ServiceStatusTile(this.status, {super.key}); |
| 11 | |
| 12 | @override |
| 13 | Widget build(BuildContext context) { |
| 14 | return ListTile( |
| 15 | contentPadding: const EdgeInsets.all(8), |
| 16 | title: Padding( |
| 17 | padding: const EdgeInsets.symmetric(vertical: 8), |
| 18 | child: Row( |
| 19 | crossAxisAlignment: CrossAxisAlignment.end, |
| 20 | children: [ |
| 21 | Expanded( |
| 22 | child: AutoSizeText( |
| 23 | "${status.title}${status.status != null ? " - ${status.status}" : ""}", |
| 24 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 25 | fontSize: 16, |
| 26 | fontWeight: FontWeight.w800, |
| 27 | height: 1, |
| 28 | ), |
| 29 | maxLines: 1, |
| 30 | textAlign: TextAlign.start, |
| 31 | ), |
| 32 | ), |
| 33 | Text( |
| 34 | _getTimeString(status.date), |
| 35 | style: Theme.of(context).textTheme.bodySmall, |
| 36 | ), |
| 37 | ], |
| 38 | ), |
| 39 | ), |
| 40 | leading: RotatedBox( |
| 41 | child: Icon( |
| 42 | Icons.info, |
| 43 | color: status.status == "resolved" |
| 44 | ? CustomThemeColors.syncGreen |
| 45 | : Theme.of(context).colorScheme.errorContainer, |
| 46 | ), |
| 47 | quarterTurns: 2, |
| 48 | ), |
| 49 | subtitle: Row( |
| 50 | children: [ |
| 51 | Expanded(child: Text(status.description)), |
| 52 | if (status.image != null) |
| 53 | SizedBox( |
| 54 | height: 50, |
| 55 | width: 50, |
| 56 | child: Image.network(status.image!), |
| 57 | ), |
| 58 | ], |
| 59 | ), |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | String _getTimeString(DateTime date) { |
| 64 | int difference = DateTime.now().difference(date).inHours; |
| 65 | if (difference == 0) { |
| 66 | return "few minutes ago"; |
| 67 | } |
| 68 | if (difference < 24) { |
| 69 | return DateFormat('h:mm a').format(date); |
| 70 | } |
| 71 | return DateFormat('d-MM-yyyy').format(date); |
| 72 | } |
| 73 | } |