243 lines
7.3 KiB
Dart
243 lines
7.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../providers/user_provider.dart';
|
|
|
|
class ProfileContent extends StatelessWidget {
|
|
const ProfileContent({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer<UserProvider>(
|
|
builder: (context, userProvider, child) {
|
|
final user = userProvider.currentUser;
|
|
|
|
if (user == null) {
|
|
return Center(child: Text('Aucun utilisateur connecté'));
|
|
}
|
|
|
|
return Column(
|
|
children: [
|
|
// Section titre
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'Profil utilisateur',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.grey[600],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// Card du profil
|
|
Card(
|
|
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Padding(
|
|
padding: EdgeInsets.all(16),
|
|
child: Column(
|
|
children: [
|
|
// Photo de profil
|
|
CircleAvatar(
|
|
radius: 40,
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
child: Text(
|
|
user.prenom[0].toUpperCase() +
|
|
user.nom[0].toUpperCase(),
|
|
style: TextStyle(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
// Nom complet
|
|
Text(
|
|
user.fullName,
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
|
|
SizedBox(height: 8),
|
|
|
|
// Email
|
|
Text(
|
|
user.email,
|
|
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
// Actions du profil
|
|
ListTile(
|
|
leading: Icon(Icons.edit),
|
|
title: Text('Modifier le profil'),
|
|
trailing: Icon(Icons.arrow_forward_ios),
|
|
onTap: () {
|
|
_showEditProfileDialog(context, user);
|
|
},
|
|
),
|
|
|
|
ListTile(
|
|
leading: Icon(Icons.lock),
|
|
title: Text('Changer le mot de passe'),
|
|
trailing: Icon(Icons.arrow_forward_ios),
|
|
onTap: () {
|
|
_showChangePasswordDialog(context);
|
|
},
|
|
),
|
|
|
|
Divider(),
|
|
|
|
ListTile(
|
|
leading: Icon(Icons.delete, color: Colors.red),
|
|
title: Text('Supprimer le compte'),
|
|
trailing: Icon(Icons.arrow_forward_ios),
|
|
onTap: () {
|
|
_showDeleteAccountDialog(context);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _showEditProfileDialog(BuildContext context, user) {
|
|
final nomController = TextEditingController(text: user.nom);
|
|
final prenomController = TextEditingController(text: user.prenom);
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text('Modifier le profil'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
controller: prenomController,
|
|
decoration: InputDecoration(labelText: 'Prénom'),
|
|
),
|
|
SizedBox(height: 16),
|
|
TextField(
|
|
controller: nomController,
|
|
decoration: InputDecoration(labelText: 'Nom'),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text('Annuler'),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
// TODO: Implémenter la mise à jour
|
|
Navigator.of(context).pop();
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text('Profil mis à jour !')));
|
|
},
|
|
child: Text('Sauvegarder'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _showChangePasswordDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text('Changer le mot de passe'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
obscureText: true,
|
|
decoration: InputDecoration(labelText: 'Mot de passe actuel'),
|
|
),
|
|
SizedBox(height: 16),
|
|
TextField(
|
|
obscureText: true,
|
|
decoration: InputDecoration(labelText: 'Nouveau mot de passe'),
|
|
),
|
|
SizedBox(height: 16),
|
|
TextField(
|
|
obscureText: true,
|
|
decoration: InputDecoration(
|
|
labelText: 'Confirmer le mot de passe',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text('Annuler'),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
// TODO: Implémenter le changement de mot de passe
|
|
Navigator.of(context).pop();
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Mot de passe changé !')),
|
|
);
|
|
},
|
|
child: Text('Changer'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _showDeleteAccountDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text('Supprimer le compte'),
|
|
content: Text(
|
|
'Êtes-vous sûr de vouloir supprimer votre compte ? Cette action est irréversible.',
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text('Annuler'),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
// TODO: Implémenter la suppression
|
|
Provider.of<UserProvider>(context, listen: false).logout();
|
|
Navigator.pushNamedAndRemoveUntil(
|
|
context,
|
|
'/login',
|
|
(route) => false,
|
|
);
|
|
},
|
|
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
|
child: Text('Supprimer'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|