Enhances the SMS message widget to provide a richer user experience. Adds sender information, formatted date, message processing status and actions. Includes localization support for new UI elements.
116 lines
4.3 KiB
Dart
116 lines
4.3 KiB
Dart
import 'package:budget_app/l10n/app_localizations.dart';
|
|
import 'package:budget_app/models/sms_message.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
/// Виджет для отображения одного SMS сообщения с улучшенным интерфейсом.
|
|
///
|
|
/// Отображает отправителя, дату, тело сообщения и статус обработки.
|
|
/// Подсвечивает суммы в тексте сообщения.
|
|
class SmsMessageWidget extends StatelessWidget {
|
|
final SmsMessage message;
|
|
|
|
const SmsMessageWidget({super.key, required this.message});
|
|
|
|
// Форматирование даты для отображения
|
|
String _formatDate(BuildContext context, DateTime? date) {
|
|
if (date == null) return '';
|
|
final locale = Localizations.localeOf(context).toString();
|
|
return DateFormat.yMd(locale).add_jm().format(date);
|
|
}
|
|
|
|
// Функция для отображения всплывающего меню
|
|
void _showPopupMenu(BuildContext context, TapDownDetails details) {
|
|
final RenderBox overlay =
|
|
Overlay.of(context).context.findRenderObject() as RenderBox;
|
|
showMenu(
|
|
context: context,
|
|
position: RelativeRect.fromRect(
|
|
details.globalPosition & const Size(40, 40),
|
|
Offset.zero & overlay.size,
|
|
),
|
|
items: [
|
|
PopupMenuItem(
|
|
child: Text(AppLocalizations.of(context)!.smsSettings),
|
|
onTap: () {
|
|
// TODO: Реализовать переход к настройкам обработки SMS
|
|
},
|
|
),
|
|
PopupMenuItem(
|
|
child: Text(AppLocalizations.of(context)!.createTransaction),
|
|
onTap: () {
|
|
// TODO: Реализовать создание транзакции из SMS
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTapDown: (details) => _showPopupMenu(context, details),
|
|
child: Card(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Заголовок: отправитель и дата
|
|
Row(
|
|
children: [
|
|
Icon(Icons.person_outline, size: 16),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
message.sender ?? AppLocalizations.of(context)!.unknownSender,
|
|
style: Theme.of(context).textTheme.titleSmall,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Text(
|
|
_formatDate(context, message.date),
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
|
|
// Тело сообщения с подсветкой сумм
|
|
Text(
|
|
message.body ?? '',
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
),
|
|
const SizedBox(height: 12),
|
|
|
|
// Футер: статус обработки
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
message.transactionId != null
|
|
? Icons.check_circle_outline
|
|
: Icons.error_outline,
|
|
size: 16,
|
|
color: message.transactionId != null
|
|
? Theme.of(context).colorScheme.primary
|
|
: Theme.of(context).colorScheme.error,
|
|
),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
message.transactionId != null
|
|
? AppLocalizations.of(context)!.smsProcessed
|
|
: AppLocalizations.of(context)!.smsNotProcessed,
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|