Overview
TheEditProfileScreen allows users to update their profile information including name, surname, email, password, and profile photo.
File: lib/ui/screens/edit_profile_screen.dart
Purpose
Provides functionality to:- View current profile information
- Update name and surname
- Change email address
- Update password with reauthentication
- Upload or change profile photo
- Store updated data in Firestore and Firebase Auth
Key Components
State Variables
Firebase Auth instance for authentication operations
Firestore instance for profile data storage
Firebase Storage for profile image uploads
Controls the name input field
Controls the surname input field
Controls the email input field
Controls the password input field (for reauthentication)
Current profile photo URL from Firebase Storage
Newly selected profile image file
Key Methods
_loadUserData()
Loads current user profile data on initialization:lib/ui/screens/edit_profile_screen.dart:38
_pickImage()
Allows user to select a new profile photo from gallery:lib/ui/screens/edit_profile_screen.dart:58
_updateProfile()
Handles the complete profile update process:- Reauthentication (if password provided)
- Email Update (if changed)
- Profile Image Upload (if new image selected)
- Firestore Update (name, surname, photoUrl)
lib/ui/screens/edit_profile_screen.dart:68
UI Structure
Profile Photo Section
- Current Photo Display - CircleAvatar showing existing photo or placeholder
- Change Photo Button - Opens image picker gallery
- Image Preview - Shows newly selected image before upload
Form Fields
- Name Field - TextFormField with current name
- Surname Field - TextFormField with current surname
- Email Field - TextFormField with current email (requires reauthentication to change)
- Password Field - Optional field for reauthentication
Actions
- Save Button - Submits profile updates
- Cancel/Back Button - Returns without saving
Data Flow
Profile Image Storage
Storage Path
Profile images are stored at:Upload Process
- User selects image from gallery
- Image stored temporarily as File object
- On save, image uploaded to Firebase Storage
- Download URL retrieved and stored in Firestore
- Old image automatically replaced (same path)
Security Considerations
Reauthentication
Required for sensitive operations:- Changing email address
- Updating password
Error Handling
- Invalid credentials: Shows error message
- Network errors: Gracefully handled with user feedback
- Upload failures: Reverted with error notification
- Email already in use: Firebase error displayed
Best Practices
- Always Reauthenticate: Before sensitive operations like email change
- Validate Email Format: Ensure valid email before submission
- Compress Images: Consider image optimization before upload
- Handle Mounted State: Check widget mounted before UI updates
- Clear Password Field: Don’t persist password in controller
- Show Loading State: Display progress during upload/update
Validation Rules
- Name: Required, non-empty
- Surname: Required, non-empty
- Email: Valid email format required
- Password: Required for email changes, minimum 6 characters
- Photo: Optional, supports common image formats
Related Components
User Profiles
User profile feature documentation
Firebase Storage
Storage configuration guide
Authentication
Authentication feature overview
TaskScreen
Main dashboard with profile access