Files
Finlytic/FinlyticApp/lib/features/calendar/widgets/calendar_event_tile.dart
T

119 lines
4.2 KiB
Dart

import 'package:flutter/material.dart';
import '../../../core/network/api_client.dart';
import '../../../core/theme/app_theme.dart';
import '../../../core/widgets/asset_logo_widget.dart';
import '../../../core/widgets/glass_container.dart';
import '../../../core/widgets/status_badge.dart';
import '../../asset_detail/views/asset_detail_screen.dart';
/// Glassmorphic Event Tile widget for Corporate Calendar (Kachelansicht).
class CalendarEventTile extends StatelessWidget {
final Map<String, dynamic> event;
final ApiClient apiClient;
const CalendarEventTile({
super.key,
required this.event,
required this.apiClient,
});
@override
Widget build(BuildContext context) {
final isin = event['isin']!;
final rawSymbol = event['ticker']?.toString() ?? event['Ticker']?.toString() ?? event['symbol']?.toString() ?? 'ASSET';
final companyName = event['companyName']?.toString() ?? event['CompanyName']?.toString() ?? rawSymbol;
final type = event['eventType']?.toString() ?? event['EventType']?.toString() ?? 'Earnings';
final desc = event['description']?.toString() ?? event['Description']?.toString() ?? '$companyName $type Termin';
final dateStr = event['date']?.toString() ?? event['Date']?.toString() ?? event['eventDate']?.toString() ?? '';
final image = event['image']?.toString() ?? (isin.isNotEmpty ? '/api/v1/logo/$isin' : null);
String formattedDate = dateStr;
try {
final dt = DateTime.parse(dateStr);
formattedDate = '${dt.day.toString().padLeft(2, '0')}.${dt.month.toString().padLeft(2, '0')}.${dt.year}';
} catch (_) {}
Color badgeColor = AppTheme.primaryEmerald;
String typeLabel = 'Quartalszahlen';
if (type == 'ExDividend') {
badgeColor = AppTheme.accentCyan;
typeLabel = 'Ex-Dividende';
} else if (type == 'Payout') {
badgeColor = Colors.amber;
typeLabel = 'Zahlungstag';
}
return GlassContainer(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => AssetDetailScreen(
isin: isin,
name: companyName,
symbol: rawSymbol,
apiClient: apiClient,
),
),
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Row(
children: [
AssetLogoWidget(symbolOrName: isin.isNotEmpty ? isin : companyName, imageUrl: image, size: 28, enableHero: false),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
companyName,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13.5),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
rawSymbol,
style: TextStyle(color: AppTheme.textMuted, fontSize: 10),
),
],
),
),
],
),
),
StatusBadge(label: typeLabel, color: badgeColor),
],
),
const SizedBox(height: 6),
Text(
desc,
style: TextStyle(color: AppTheme.textSecondary, fontSize: 12),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 6),
Row(
children: [
Text('Termin:', style: TextStyle(color: AppTheme.textMuted, fontSize: 10.5)),
const SizedBox(width: 6),
Text(
formattedDate,
style: TextStyle(color: AppTheme.accentCyan, fontWeight: FontWeight.bold, fontSize: 11),
),
],
),
],
),
);
}
}