Files
afterwork/lib/presentation/widgets/event_header.dart
2024-11-17 23:00:18 +00:00

124 lines
3.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:afterwork/core/utils/date_formatter.dart';
import 'event_menu.dart';
class EventHeader extends StatelessWidget {
final String creatorFirstName;
final String creatorLastName;
final String profileImageUrl;
final String? eventDate;
final String? imageUrl;
final String location;
final GlobalKey menuKey;
final BuildContext menuContext;
final VoidCallback onClose; // Ajout d'un callback pour l'action de fermeture
const EventHeader({
Key? key,
required this.creatorFirstName,
required this.creatorLastName,
required this.profileImageUrl,
this.eventDate,
this.imageUrl,
required this.location,
required this.menuKey,
required this.menuContext,
required this.onClose, // Initialisation du callback de fermeture
}) : super(key: key);
@override
Widget build(BuildContext context) {
DateTime? date;
try {
date = DateTime.parse(eventDate ?? '');
} catch (e) {
date = null;
}
String formattedDate = date != null ? DateFormatter.formatDate(date) : 'Date inconnue';
return Stack(
children: [
Row(
children: [
CircleAvatar(
backgroundColor: Colors.grey.shade800,
backgroundImage: profileImageUrl.isNotEmpty
? NetworkImage(profileImageUrl)
: AssetImage(profileImageUrl) as ImageProvider,
radius: 22,
),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'$creatorFirstName $creatorLastName',
style: const TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w500,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
formattedDate,
style: const TextStyle(
color: Colors.white54,
fontSize: 12,
),
),
const SizedBox(height: 4),
Row(
children: [
Expanded(
child: Text(
location.isNotEmpty ? location : 'Lieu non spécifié',
style: const TextStyle(
color: Colors.white60,
fontSize: 12,
fontStyle: FontStyle.italic,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
],
),
],
),
),
],
),
// Placement des icônes avec padding pour éviter qu'elles ne soient trop proches du bord
Positioned(
top: 0,
right: -5,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
key: menuKey,
icon: const Icon(Icons.more_vert, color: Colors.white54, size: 20),
splashRadius: 20,
onPressed: () {
showEventOptions(menuContext, menuKey);
},
),
const SizedBox(width: 0), // Espacement entre les icônes
IconButton(
icon: const Icon(Icons.close, color: Colors.white54, size: 20),
splashRadius: 20,
onPressed: onClose, // Appel du callback de fermeture
),
],
),
),
],
);
}
}