Add phone number field to UserModel and update ProfileContent to display user phone number
This commit is contained in:
@@ -75,16 +75,20 @@ class UserModel {
|
|||||||
/// Platform used for authentication (e.g., 'google', 'apple', 'email').
|
/// Platform used for authentication (e.g., 'google', 'apple', 'email').
|
||||||
final String? authMethod;
|
final String? authMethod;
|
||||||
|
|
||||||
|
/// User's phone number (optional).
|
||||||
|
final String? phoneNumber;
|
||||||
|
|
||||||
/// Creates a new [UserModel] instance.
|
/// Creates a new [UserModel] instance.
|
||||||
///
|
///
|
||||||
/// [id], [email], and [prenom] are required fields.
|
/// [id], [email], and [prenom] are required fields.
|
||||||
/// [nom] and [authMethod] are optional and can be null.
|
/// [nom], [authMethod], and [phoneNumber] are optional and can be null.
|
||||||
UserModel({
|
UserModel({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.email,
|
required this.email,
|
||||||
required this.prenom,
|
required this.prenom,
|
||||||
this.nom,
|
this.nom,
|
||||||
this.authMethod,
|
this.authMethod,
|
||||||
|
this.phoneNumber,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Creates a [UserModel] instance from a JSON map.
|
/// Creates a [UserModel] instance from a JSON map.
|
||||||
@@ -98,6 +102,7 @@ class UserModel {
|
|||||||
prenom: json['prenom'] ?? 'Voyageur',
|
prenom: json['prenom'] ?? 'Voyageur',
|
||||||
nom: json['nom'],
|
nom: json['nom'],
|
||||||
authMethod: json['authMethod'] ?? json['platform'],
|
authMethod: json['authMethod'] ?? json['platform'],
|
||||||
|
phoneNumber: json['phoneNumber'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +116,7 @@ class UserModel {
|
|||||||
'prenom': prenom,
|
'prenom': prenom,
|
||||||
'nom': nom,
|
'nom': nom,
|
||||||
'authMethod': authMethod,
|
'authMethod': authMethod,
|
||||||
|
'phoneNumber': phoneNumber,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,47 +18,43 @@ class ProfileContent extends StatelessWidget {
|
|||||||
builder: (context, user) {
|
builder: (context, user) {
|
||||||
final isEmailAuth = user.authMethod == 'email' || user.authMethod == null;
|
final isEmailAuth = user.authMethod == 'email' || user.authMethod == null;
|
||||||
|
|
||||||
return Column(
|
return SingleChildScrollView(
|
||||||
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(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
// En-tête avec photo de profil
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 24, horizontal: 16),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
// Photo de profil
|
// Photo de profil
|
||||||
CircleAvatar(
|
Container(
|
||||||
radius: 40,
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.1),
|
||||||
|
blurRadius: 8,
|
||||||
|
offset: Offset(0, 2),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: CircleAvatar(
|
||||||
|
radius: 50,
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
child: Text(
|
child: Text(
|
||||||
user.prenom.isNotEmpty
|
user.prenom.isNotEmpty
|
||||||
? user.prenom[0].toUpperCase()
|
? user.prenom[0].toUpperCase()
|
||||||
: 'U',
|
: 'U',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 24,
|
fontSize: 32,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
|
|
||||||
@@ -66,17 +62,22 @@ class ProfileContent extends StatelessWidget {
|
|||||||
Text(
|
Text(
|
||||||
'${user.prenom} ${user.nom ?? ''}',
|
'${user.prenom} ${user.nom ?? ''}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 22,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
|
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 4),
|
||||||
|
|
||||||
// Email
|
// Email
|
||||||
Text(
|
Text(
|
||||||
user.email,
|
user.email,
|
||||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Colors.grey[600],
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
|
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
@@ -91,11 +92,13 @@ class ProfileContent extends StatelessWidget {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
|
if (_getAuthMethodIcon(user.authMethod).isNotEmpty)
|
||||||
Image.asset(
|
Image.asset(
|
||||||
_getAuthMethodIcon(user.authMethod),
|
_getAuthMethodIcon(user.authMethod),
|
||||||
height: 16,
|
height: 16,
|
||||||
width: 16,
|
width: 16,
|
||||||
),
|
),
|
||||||
|
if (_getAuthMethodIcon(user.authMethod).isNotEmpty)
|
||||||
SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
Text(
|
Text(
|
||||||
_getAuthMethodLabel(user.authMethod),
|
_getAuthMethodLabel(user.authMethod),
|
||||||
@@ -111,45 +114,208 @@ class ProfileContent extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Section Informations personnelles
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Informations personnelles',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Actions du profil
|
// Tuiles d'information
|
||||||
ListTile(
|
_buildInfoTile(
|
||||||
leading: Icon(Icons.edit),
|
icon: Icons.person_outline,
|
||||||
title: Text('Modifier le profil'),
|
label: 'Nom complet',
|
||||||
trailing: Icon(Icons.arrow_forward_ios),
|
value: '${user.prenom} ${user.nom ?? ''}',
|
||||||
onTap: () {
|
context: context,
|
||||||
_showEditProfileDialog(context, user);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
|
||||||
// Afficher l'option de changement de mot de passe seulement pour email
|
_buildInfoTile(
|
||||||
|
icon: Icons.email_outlined,
|
||||||
|
label: 'Adresse e-mail',
|
||||||
|
value: user.email,
|
||||||
|
context: context,
|
||||||
|
),
|
||||||
|
|
||||||
|
_buildInfoTile(
|
||||||
|
icon: Icons.phone_outlined,
|
||||||
|
label: 'Téléphone',
|
||||||
|
value: user.phoneNumber ?? 'Non défini',
|
||||||
|
context: context,
|
||||||
|
),
|
||||||
|
|
||||||
|
// Option de changement de mot de passe seulement pour email
|
||||||
if (isEmailAuth)
|
if (isEmailAuth)
|
||||||
ListTile(
|
_buildActionTile(
|
||||||
leading: Icon(Icons.lock),
|
icon: Icons.lock_outlined,
|
||||||
title: Text('Changer le mot de passe'),
|
label: 'Changer de mot de passe',
|
||||||
trailing: Icon(Icons.arrow_forward_ios),
|
context: context,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_showChangePasswordDialog(context, user);
|
_showChangePasswordDialog(context, user);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
Divider(),
|
SizedBox(height: 8),
|
||||||
|
|
||||||
ListTile(
|
// Option pour modifier le profil
|
||||||
leading: Icon(Icons.delete, color: Colors.red),
|
_buildActionTile(
|
||||||
title: Text('Supprimer le compte'),
|
icon: Icons.edit_outlined,
|
||||||
trailing: Icon(Icons.arrow_forward_ios),
|
label: 'Modifier le profil',
|
||||||
|
context: context,
|
||||||
|
onTap: () {
|
||||||
|
_showEditProfileDialog(context, user);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 8),
|
||||||
|
|
||||||
|
// Option pour supprimer le compte
|
||||||
|
_buildActionTile(
|
||||||
|
icon: Icons.delete_outline,
|
||||||
|
label: 'Supprimer le compte',
|
||||||
|
context: context,
|
||||||
|
isDestructive: true,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_showDeleteAccountDialog(context, user);
|
_showDeleteAccountDialog(context, user);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 24),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildInfoTile({
|
||||||
|
required IconData icon,
|
||||||
|
required String label,
|
||||||
|
required String value,
|
||||||
|
required BuildContext context,
|
||||||
|
}) {
|
||||||
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: isDarkMode ? Colors.grey[850] : Colors.grey[100],
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: isDarkMode ? Colors.grey[800] : Colors.grey[200],
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
icon,
|
||||||
|
size: 20,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Colors.grey[600],
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 2),
|
||||||
|
Text(
|
||||||
|
value,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: isDarkMode ? Colors.white : Colors.black87,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildActionTile({
|
||||||
|
required IconData icon,
|
||||||
|
required String label,
|
||||||
|
required BuildContext context,
|
||||||
|
required VoidCallback onTap,
|
||||||
|
bool isDestructive = false,
|
||||||
|
}) {
|
||||||
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: isDarkMode ? Colors.grey[850] : Colors.grey[100],
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: isDarkMode ? Colors.grey[800] : Colors.grey[200],
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
icon,
|
||||||
|
size: 20,
|
||||||
|
color: isDestructive
|
||||||
|
? Colors.red
|
||||||
|
: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: isDestructive
|
||||||
|
? Colors.red
|
||||||
|
: (isDarkMode ? Colors.white : Colors.black87),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
size: 16,
|
||||||
|
color: Colors.grey[400],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
String _getAuthMethodLabel(String? authMethod) {
|
String _getAuthMethodLabel(String? authMethod) {
|
||||||
switch (authMethod) {
|
switch (authMethod) {
|
||||||
case 'apple':
|
case 'apple':
|
||||||
|
|||||||
Reference in New Issue
Block a user