110 lines
4.1 KiB
Dart
110 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../../../core/constants/colors.dart';
|
|
import '../../../../data/providers/user_provider.dart';
|
|
import '../../../../domain/entities/user.dart';
|
|
|
|
/// [ProfileHeader] est un widget qui affiche l'en-tête du profil utilisateur.
|
|
/// Comprend le nom de l'utilisateur, une image de fond, et un bouton de déconnexion avec confirmation.
|
|
class ProfileHeader extends StatelessWidget {
|
|
final User user;
|
|
|
|
const ProfileHeader({Key? key, required this.user}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SliverAppBar(
|
|
expandedHeight: 200.0,
|
|
floating: false,
|
|
pinned: true,
|
|
backgroundColor: AppColors.darkPrimary,
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
title: Text(
|
|
'Profil de ${user.userFirstName}',
|
|
style: TextStyle(
|
|
color: AppColors.accentColor,
|
|
fontSize: 20.0,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
background: Image.network(
|
|
user.profileImageUrl,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
// Log en cas d'erreur de chargement de l'image
|
|
print("[ERROR] Erreur lors du chargement de l'image de profil : $error");
|
|
return Image.asset('lib/assets/images/default_avatar.png', fit: BoxFit.cover);
|
|
},
|
|
),
|
|
),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.logout, color: Colors.white),
|
|
onPressed: () {
|
|
print("[LOG] Bouton de déconnexion cliqué."); // Log du clic du bouton de déconnexion
|
|
_showLogoutConfirmationDialog(context); // Affiche le dialogue de confirmation
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// Affiche une boîte de dialogue de confirmation pour la déconnexion.
|
|
/// Log chaque action et résultat dans le terminal.
|
|
void _showLogoutConfirmationDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
// Log affichage du dialogue
|
|
print("[LOG] Affichage de la boîte de dialogue de confirmation de déconnexion.");
|
|
|
|
return AlertDialog(
|
|
backgroundColor: AppColors.backgroundColor,
|
|
title: const Text(
|
|
'Confirmer la déconnexion',
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
content: const Text(
|
|
'Voulez-vous vraiment vous déconnecter ?',
|
|
style: TextStyle(color: Colors.white70),
|
|
),
|
|
actions: [
|
|
// Bouton d'annulation de la déconnexion
|
|
TextButton(
|
|
onPressed: () {
|
|
print("[LOG] Déconnexion annulée par l'utilisateur.");
|
|
Navigator.of(context).pop(); // Ferme le dialogue sans déconnecter
|
|
},
|
|
child: Text(
|
|
'Annuler',
|
|
style: TextStyle(color: AppColors.accentColor),
|
|
),
|
|
),
|
|
// Bouton de confirmation de la déconnexion
|
|
TextButton(
|
|
onPressed: () {
|
|
print("[LOG] Déconnexion confirmée."); // Log de la confirmation
|
|
Provider.of<UserProvider>(context, listen: false).resetUser(); // Réinitialise les infos utilisateur
|
|
print("[LOG] Informations utilisateur réinitialisées dans UserProvider.");
|
|
|
|
Navigator.of(context).pop(); // Ferme la boîte de dialogue
|
|
print("[LOG] Boîte de dialogue de confirmation fermée.");
|
|
|
|
Navigator.of(context).pushReplacementNamed('/'); // Redirige vers l'écran de connexion
|
|
print("[LOG] Redirection vers l'écran de connexion.");
|
|
},
|
|
child: const Text(
|
|
'Déconnexion',
|
|
style: TextStyle(color: Colors.redAccent),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
).then((_) {
|
|
// Log lorsque le dialogue est fermé pour toute raison (confirmation ou annulation)
|
|
print("[LOG] La boîte de dialogue de confirmation de déconnexion est fermée.");
|
|
});
|
|
}
|
|
}
|