UserModel.fromSnapshot constructor
- DocumentSnapshot<
Map< documentString, dynamic> >
Map Json oriented document snapshot from Firebase to UserModel
Implementation
factory UserModel.fromSnapshot(DocumentSnapshot<Map<String, dynamic>> document) {
// If document is empty then return an empty Model as created above.
if(document.data() == null || document.data()!.isEmpty) return UserModel.empty();
final data = document.data()!;
return UserModel(
id: document.id,
email: data["email"],
userName: data["username"],
fullName: data["fullName"],
createdAt: data["createdAt"],
updatedAt: data["updatedAt"],
fitnessLevel: data["fitnessLevel"] ?? "beginner",
completedExercises: data["completedExercises"] ?? 0,
profilePicture: data["profilePicture"] ?? "",
role: data["role"] ?? "user",
);
}