120 lines
3.7 KiB
Dart
120 lines
3.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../core/constants/colors.dart';
|
|
import '../../../data/models/social_post_model.dart';
|
|
import 'social_badge_widget.dart'; // Import du widget BadgeWidget
|
|
|
|
class SocialHeaderWidget extends StatelessWidget {
|
|
final SocialPost post;
|
|
final VoidCallback onEditPost;
|
|
final VoidCallback onClosePost; // Ajout du callback pour la fermeture du post
|
|
final GlobalKey menuKey;
|
|
final BuildContext menuContext;
|
|
|
|
const SocialHeaderWidget({
|
|
Key? key,
|
|
required this.post,
|
|
required this.onEditPost,
|
|
required this.onClosePost, // Initialisation du callback de fermeture
|
|
required this.menuKey,
|
|
required this.menuContext,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
CircleAvatar(
|
|
backgroundColor: Colors.grey.shade800,
|
|
backgroundImage: post.userImage.isNotEmpty
|
|
? AssetImage(post.userImage)
|
|
: const AssetImage('lib/assets/images/placeholder.png'),
|
|
radius: 22,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
post.userName,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Wrap(
|
|
spacing: 6,
|
|
children: post.badges
|
|
.map((badge) => BadgeWidget(badge: badge))
|
|
.toList(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
// Ajout des boutons dans le coin supérieur droit
|
|
Positioned(
|
|
top: 0,
|
|
right: 0,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min, // Réduit la taille du Row au minimum
|
|
children: [
|
|
IconButton(
|
|
key: menuKey,
|
|
icon: const Icon(Icons.more_vert, color: Colors.white54, size: 20),
|
|
splashRadius: 20,
|
|
onPressed: () {
|
|
_showOptionsMenu(menuContext, menuKey);
|
|
},
|
|
),
|
|
const SizedBox(width: 4), // Espacement entre les boutons
|
|
IconButton(
|
|
icon: const Icon(Icons.close, color: Colors.white54, size: 20),
|
|
splashRadius: 20,
|
|
onPressed: onClosePost, // Appel du callback de fermeture
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void _showOptionsMenu(BuildContext context, GlobalKey menuKey) {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
builder: (context) {
|
|
return Container(
|
|
color: AppColors.backgroundColor,
|
|
child: Wrap(
|
|
children: <Widget>[
|
|
ListTile(
|
|
leading: Icon(Icons.edit, color: AppColors.iconPrimary),
|
|
title: const Text('Modifier'),
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
onEditPost();
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: Icon(Icons.delete, color: AppColors.iconPrimary),
|
|
title: const Text('Supprimer'),
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|