Files
EM2_ERP/em2rp/lib/widgets/event_details.dart

173 lines
5.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:em2rp/models/event_model.dart';
import 'package:em2rp/utils/colors.dart';
import 'package:intl/intl.dart';
class EventDetails extends StatelessWidget {
final EventModel event;
final DateTime? selectedDate;
final List<EventModel> events;
final void Function(EventModel, DateTime) onSelectEvent;
const EventDetails({
super.key,
required this.event,
required this.selectedDate,
required this.events,
required this.onSelectEvent,
});
@override
Widget build(BuildContext context) {
final dateFormat = DateFormat('dd/MM/yyyy HH:mm');
final currencyFormat = NumberFormat.currency(locale: 'fr_FR', symbol: '');
final fullDateFormat = DateFormat('EEEE d MMMM y', 'fr_FR');
// Trie les événements par date de début
final sortedEvents = List<EventModel>.from(events)
..sort((a, b) => a.startDateTime.compareTo(b.startDateTime));
final currentIndex = sortedEvents.indexWhere((e) => e.id == event.id);
return Card(
margin: const EdgeInsets.all(16),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: currentIndex > 0
? () {
final prevEvent = sortedEvents[currentIndex - 1];
onSelectEvent(prevEvent, prevEvent.startDateTime);
}
: null,
icon: const Icon(Icons.arrow_back),
color: AppColors.rouge,
),
if (selectedDate != null)
Expanded(
child: Center(
child: Text(
fullDateFormat.format(selectedDate!),
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: AppColors.rouge,
fontWeight: FontWeight.bold,
),
),
),
),
IconButton(
onPressed: currentIndex < sortedEvents.length - 1
? () {
final nextEvent = sortedEvents[currentIndex + 1];
onSelectEvent(nextEvent, nextEvent.startDateTime);
}
: null,
icon: const Icon(Icons.arrow_forward),
color: AppColors.rouge,
),
],
),
const SizedBox(height: 16),
Text(
event.name,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: AppColors.noir,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
_buildInfoRow(
context,
Icons.calendar_today,
'Date de début',
dateFormat.format(event.startDateTime),
),
_buildInfoRow(
context,
Icons.calendar_today,
'Date de fin',
dateFormat.format(event.endDateTime),
),
_buildInfoRow(
context,
Icons.euro,
'Prix',
currencyFormat.format(event.price),
),
_buildInfoRow(
context,
Icons.build,
'Temps d\'installation',
'${event.installationTime} heures',
),
_buildInfoRow(
context,
Icons.construction,
'Temps de démontage',
'${event.disassemblyTime} heures',
),
const SizedBox(height: 16),
Text(
'Description',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: AppColors.noir,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
event.description,
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(height: 16),
Text(
'Adresse',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: AppColors.noir,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
'${event.address.latitude}° N, ${event.address.longitude}° E',
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),
);
}
Widget _buildInfoRow(
BuildContext context,
IconData icon,
String label,
String value,
) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
Icon(icon, color: AppColors.rouge),
const SizedBox(width: 8),
Text(
'$label : ',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: AppColors.noir,
fontWeight: FontWeight.bold,
),
),
Text(
value,
style: Theme.of(context).textTheme.titleMedium,
),
],
),
);
}
}