Class Overview
TheUserProfile class is a Flutter model that represents user information in the application. It provides methods for serialization and deserialization with Firestore.
Location: lib/models/user_profile.dart
Properties
Unique identifier for the user. This is typically the Firebase Auth user ID.
The user’s first name.
The user’s last name or surname.
Optional URL to the user’s profile photo. Can be null if no photo is set.
Constructor
UserProfile instance with the specified properties.
Parameters
- uid (required): The unique user identifier
- name (required): The user’s first name
- surname (required): The user’s last name
- photoUrl (optional): URL to the user’s profile photo
Methods
fromFirestore()
UserProfile instance from Firestore document data.
Parameters:
data- Map containing the Firestore document fieldsuid- The user’s unique identifier
UserProfile instance
Example:
toMap()
UserProfile instance to a Map suitable for saving to Firestore.
Returns: A Map containing the user’s name, surname, and photoUrl (excluding uid)
Example:
Usage in Authentication Flow
TheUserProfile model is commonly used during user registration and profile management:
Creating a User Profile
Fetching User Profile
Updating User Profile
Notes
- The
uidfield is not included in thetoMap()output since it’s used as the document ID in Firestore - The
photoUrlfield is optional and can benull - Default empty strings are used for
nameandsurnameif the Firestore data doesn’t contain these fields - The model includes an
emailgetter that always returnsnull(line 26)