Page profile OK
This commit is contained in:
parent
c579fd92a2
commit
471d6c5eef
14
em2rp/.vscode/launch.json
vendored
14
em2rp/.vscode/launch.json
vendored
@ -5,6 +5,20 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "Launch Edge",
|
||||
"request": "launch",
|
||||
"type": "msedge",
|
||||
"url": "http://localhost:8080",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"name": "Attach to Edge",
|
||||
"port": 9222,
|
||||
"request": "attach",
|
||||
"type": "msedge",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"name": "em2rp",
|
||||
"request": "launch",
|
||||
|
@ -40,4 +40,19 @@ class UserProvider extends ChangeNotifier {
|
||||
_phoneNumber = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setUserFirstName(String text) {
|
||||
_firstName = text;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setUserLastName(String text) {
|
||||
_lastName = text;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setUserPhoneNumber(String text) {
|
||||
_phoneNumber = text;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:em2rp/views/widgets/inputs/styled_text_field.dart';
|
||||
|
||||
class MyAccountPage extends StatefulWidget {
|
||||
const MyAccountPage({super.key});
|
||||
@ -50,11 +51,41 @@ class _MyAccountPageState extends State<MyAccountPage> {
|
||||
|
||||
Future<void> _updateUserData() async {
|
||||
if (user != null) {
|
||||
await FirebaseFirestore.instance.collection('users').doc(user!.uid).set({
|
||||
'firstName': _firstNameController.text,
|
||||
'lastName': _lastNameController.text,
|
||||
'phone': _phoneController.text,
|
||||
}, SetOptions(merge: true));
|
||||
try {
|
||||
await FirebaseFirestore.instance.collection('users').doc(user!.uid).set(
|
||||
{
|
||||
'firstName': _firstNameController.text,
|
||||
'lastName': _lastNameController.text,
|
||||
'phone': _phoneController.text,
|
||||
},
|
||||
SetOptions(merge: true),
|
||||
);
|
||||
|
||||
// **MISE À JOUR DU USERPROVIDER APRÈS SUCCÈS**
|
||||
final userProvider = Provider.of<UserProvider>(context, listen: false);
|
||||
userProvider.setUserFirstName(_firstNameController.text);
|
||||
userProvider.setUserLastName(_lastNameController.text);
|
||||
userProvider.setUserPhoneNumber(_phoneController.text);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content:
|
||||
Text('Informations personnelles mises à jour avec succès!'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Erreur lors de la mise à jour des informations personnelles: ${e.toString()}',
|
||||
),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
print(
|
||||
'Erreur lors de la mise à jour des informations utilisateur: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,6 +112,7 @@ class _MyAccountPageState extends State<MyAccountPage> {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Photo de profil mise à jour avec succès!'),
|
||||
backgroundColor: Colors.green, // Optional: Style for success
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@ -89,6 +121,7 @@ class _MyAccountPageState extends State<MyAccountPage> {
|
||||
content: Text(
|
||||
'Erreur lors de la mise à jour de la photo de profil.',
|
||||
),
|
||||
backgroundColor: Colors.red, // Optional: Style for error
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -107,80 +140,101 @@ class _MyAccountPageState extends State<MyAccountPage> {
|
||||
); // Get UserProvider instance
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Gestion du compte')),
|
||||
appBar:
|
||||
AppBar(title: const Text('Mon Compte')), // More user-friendly title
|
||||
drawer: MainDrawer(
|
||||
currentPage: '/my_account',
|
||||
userProvider: userProvider,
|
||||
), // Pass UserProvider to MainDrawer
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
MouseRegion(
|
||||
onEnter: (_) => setState(() => _isHoveringProfilePic = true),
|
||||
onExit: (_) => setState(() => _isHoveringProfilePic = false),
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap:
|
||||
_changeProfilePicture, // Call _changeProfilePicture on tap
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
ProfilePictureWidget(userId: user!.uid, radius: 45),
|
||||
if (_isHoveringProfilePic)
|
||||
Container(
|
||||
width: 140,
|
||||
height: 140,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.edit,
|
||||
color: Colors.white,
|
||||
size: 30,
|
||||
body: SingleChildScrollView(
|
||||
// Added SingleChildScrollView for better responsiveness
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(
|
||||
24.0), // Increased padding around the main content
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
MouseRegion(
|
||||
onEnter: (_) => setState(() => _isHoveringProfilePic = true),
|
||||
onExit: (_) => setState(() => _isHoveringProfilePic = false),
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap:
|
||||
_changeProfilePicture, // Call _changeProfilePicture on tap
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
ProfilePictureWidget(
|
||||
userId: user!.uid,
|
||||
radius:
|
||||
80), // Increased radius for larger profile picture
|
||||
if (_isHoveringProfilePic)
|
||||
Container(
|
||||
width: 160, // Slightly larger hover overlay
|
||||
height: 160,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.edit,
|
||||
color: Colors.white,
|
||||
size: 36, // Slightly larger edit icon
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildTextField('Prénom', _firstNameController),
|
||||
_buildTextField('Nom', _lastNameController),
|
||||
_buildTextField('Numéro de téléphone', _phoneController),
|
||||
_buildTextField(
|
||||
'Email',
|
||||
TextEditingController(text: user?.email ?? ''),
|
||||
enabled: false,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _updateUserData,
|
||||
child: const Text('Enregistrer'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField(
|
||||
String label,
|
||||
TextEditingController controller, {
|
||||
bool enabled = true,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
enabled: enabled,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: OutlineInputBorder(),
|
||||
Center(
|
||||
child: Card(
|
||||
elevation: 4.0, // Ajouter un léger relief
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(12.0)), // Bords arrondis
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(
|
||||
24.0), // Padding intérieur de la carte
|
||||
child: ConstrainedBox(
|
||||
// Limiter la largeur des inputs dans la carte
|
||||
constraints: BoxConstraints(
|
||||
maxWidth:
|
||||
500), // Ajustez la largeur maximale souhaitée
|
||||
child: Column(
|
||||
children: [
|
||||
StyledTextField(
|
||||
labelText: 'Prénom',
|
||||
controller: _firstNameController),
|
||||
const SizedBox(height: 16),
|
||||
StyledTextField(
|
||||
labelText: 'Nom',
|
||||
controller: _lastNameController),
|
||||
const SizedBox(height: 16),
|
||||
StyledTextField(
|
||||
labelText: 'Numéro de téléphone',
|
||||
controller: _phoneController),
|
||||
const SizedBox(height: 16),
|
||||
StyledTextField(
|
||||
labelText: 'Email',
|
||||
controller:
|
||||
TextEditingController(text: user?.email ?? ''),
|
||||
enabled: false,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _updateUserData,
|
||||
child: const Text('Enregistrer'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
29
em2rp/lib/views/widgets/inputs/styled_text_field.dart
Normal file
29
em2rp/lib/views/widgets/inputs/styled_text_field.dart
Normal file
@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class StyledTextField extends StatelessWidget {
|
||||
final String labelText;
|
||||
final TextEditingController controller;
|
||||
final bool enabled;
|
||||
|
||||
const StyledTextField({
|
||||
Key? key,
|
||||
required this.labelText,
|
||||
required this.controller,
|
||||
this.enabled = true,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
enabled: enabled,
|
||||
decoration: InputDecoration(
|
||||
labelText: labelText,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user