import 'package:flutter/material.dart';
import '../../core/theme/app_colors.dart';
import '../../data/app_data_scope.dart';
import '../../models/event.dart';
import '../../widgets/remote_image.dart';
import 'event_detail_page.dart';
import 'event_ui_text.dart';
class EventsPage extends StatelessWidget {
const EventsPage({super.key});
@override
Widget build(BuildContext context) {
final store = AppDataScope.of(context);
final lang = Localizations.localeOf(context).languageCode;
final t = EventUiText(lang);
final events = [...store.events]
..sort((a, b) => a.start.compareTo(b.start));
return Scaffold(
appBar: AppBar(
title: Text(t.eventsInWeimar,
style: const TextStyle(fontWeight: FontWeight.w900))),
body: events.isEmpty
? Center(
child: Padding(
padding: const EdgeInsets.all(30),
child: Text(t.noEvents, textAlign: TextAlign.center)))
: ListView.separated(
padding: const EdgeInsets.fromLTRB(16, 10, 16, 28),
itemCount: events.length,
separatorBuilder: (_, __) => const SizedBox(height: 12),
itemBuilder: (context, index) =>
EventListCard(event: events[index], languageCode: lang),
),
);
}
}
class EventListCard extends StatelessWidget {
const EventListCard(
{super.key,
required this.event,
required this.languageCode,
this.compact = false});
final Event event;
final String languageCode;
final bool compact;
@override
Widget build(BuildContext context) {
final title = event.title.get(languageCode);
final short = event.shortDescription.get(languageCode);
final t = EventUiText(languageCode);
final date = eventDateRangeLabel(context, event);
final time =
event.allDay ? t.allDayLower : eventTimeRangeLabel(context, event);
return Material(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
child: InkWell(
borderRadius: BorderRadius.circular(20),
onTap: () => Navigator.of(context).push(
MaterialPageRoute(builder: (_) => EventDetailPage(event: event))),
child: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border.all(color: AppColors.line),
borderRadius: BorderRadius.circular(20)),
child: Row(children: [
RemoteImage(
url: event.imageUrl,
width: compact ? 82 : 102,
height: compact ? 82 : 96,
fit: BoxFit.cover,
borderRadius: BorderRadius.circular(15),
fallbackIcon: Icons.event_rounded,
semanticLabel: title),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('$date · $time',
style: const TextStyle(
color: AppColors.heartRed,
fontWeight: FontWeight.w900,
fontSize: 12)),
const SizedBox(height: 4),
Text(title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.w900,
fontSize: 16,
height: 1.1)),
if (event.venueName?.trim().isNotEmpty == true) ...[
const SizedBox(height: 4),
Text(event.venueName!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.mutedInk, fontSize: 13))
],
if (!compact && short.isNotEmpty) ...[
const SizedBox(height: 4),
Text(short,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.mutedInk, fontSize: 13))
],
])),
const Icon(Icons.chevron_right_rounded),
]),
),
),
);
}
}

