Enhance user authentication handling by adding authMethod to UserModel and updating ProfileContent to display authentication method details.

This commit is contained in:
Van Leemput Dayron
2025-11-13 14:46:21 +01:00
parent dd8de46e71
commit 0971b4cb3d
3 changed files with 105 additions and 13 deletions

View File

@@ -16,6 +16,8 @@ class ProfileContent extends StatelessWidget {
Widget build(BuildContext context) {
return UserStateWrapper(
builder: (context, user) {
final isEmailAuth = user.authMethod == 'email' || user.authMethod == null;
return Column(
children: [
// Section titre
@@ -76,6 +78,36 @@ class ProfileContent extends StatelessWidget {
user.email,
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
),
SizedBox(height: 12),
// Badge de méthode de connexion
Container(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: _getAuthMethodColor(user.authMethod, context),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
_getAuthMethodIcon(user.authMethod),
height: 16,
width: 16,
),
SizedBox(width: 8),
Text(
_getAuthMethodLabel(user.authMethod),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: _getAuthMethodTextColor(user.authMethod, context),
),
),
],
),
),
],
),
),
@@ -91,14 +123,16 @@ class ProfileContent extends StatelessWidget {
},
),
ListTile(
leading: Icon(Icons.lock),
title: Text('Changer le mot de passe'),
trailing: Icon(Icons.arrow_forward_ios),
onTap: () {
_showChangePasswordDialog(context, user);
},
),
// Afficher l'option de changement de mot de passe seulement pour email
if (isEmailAuth)
ListTile(
leading: Icon(Icons.lock),
title: Text('Changer le mot de passe'),
trailing: Icon(Icons.arrow_forward_ios),
onTap: () {
_showChangePasswordDialog(context, user);
},
),
Divider(),
@@ -116,6 +150,54 @@ class ProfileContent extends StatelessWidget {
);
}
String _getAuthMethodLabel(String? authMethod) {
switch (authMethod) {
case 'apple':
return 'Connecté avec Apple';
case 'google':
return 'Connecté avec Google';
default:
return 'Connecté avec Email';
}
}
String _getAuthMethodIcon(String? authMethod) {
switch (authMethod) {
case 'apple':
return 'assets/icons/apple_white.png';
case 'google':
return 'assets/icons/google.png';
default:
return '';
}
}
Color _getAuthMethodColor(String? authMethod, BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
switch (authMethod) {
case 'apple':
return isDarkMode ? Colors.white : Colors.black87;
case 'google':
return isDarkMode ? Colors.white : Colors.black87;
default:
return isDarkMode ? Colors.white : Colors.blue;
}
}
Color _getAuthMethodTextColor(String? authMethod, BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
switch (authMethod) {
case 'apple':
return isDarkMode ? Colors.black87 : Colors.white;
case 'google':
return isDarkMode ? Colors.black87 : Colors.white;
default:
return isDarkMode ? Colors.black87 : Colors.white;
}
}
void _showEditProfileDialog(BuildContext context, user_state.UserModel user) {
final nomController = TextEditingController(text: user.nom);
final prenomController = TextEditingController(text: user.prenom);