Files
sendico/frontend/pweb/lib/pages/report/cards/operation_card.dart
2026-02-16 21:05:38 +03:00

88 lines
2.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:pshared/models/payment/operation.dart';
import 'package:pweb/pages/report/cards/operation_card_utils.dart';
import 'package:pweb/pages/report/cards/operation_info_row.dart';
import 'package:pweb/pages/report/table/badge.dart';
import 'package:pweb/utils/report/format.dart';
import 'package:pweb/utils/report/payment_mapper.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
class OperationCard extends StatelessWidget {
final OperationItem operation;
final ValueChanged<OperationItem>? onTap;
const OperationCard({
super.key,
required this.operation,
this.onTap,
});
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context)!;
final theme = Theme.of(context);
final canOpen = onTap != null && paymentIdFromOperation(operation) != null;
final amountLabel = formatAmount(operation.amount, operation.currency);
final toAmountLabel = formatAmount(operation.toAmount, operation.toCurrency);
final showToAmount = shouldShowToAmount(operation);
final timeLabel = formatOperationTime(context, operation.date);
return Card(
elevation: 0,
shape: RoundedRectangleBorder(
side: BorderSide(color: theme.dividerColor.withAlpha(25)),
borderRadius: BorderRadius.circular(16),
),
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: canOpen ? () => onTap?.call(operation) : null,
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
OperationStatusBadge(status: operation.status),
const Spacer(),
Text(
timeLabel,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
const SizedBox(height: 12),
Text(
amountLabel,
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
),
),
if (showToAmount)
Text(
loc.recipientWillReceive(toAmountLabel),
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
if ((operation.fileName ?? '').trim().isNotEmpty) ...[
const SizedBox(height: 6),
OperationInfoRow(
icon: Icons.description,
value: operation.fileName!,
),
],
],
),
),
),
);
}
}