The code for the model class is as shown below:
class UserAuthModel {
String? uid;
String? email;
String? displayName;
String? profilePic;
UserAuthModel(this.uid, this.email, this.displayName, this.profilePic);
UserAuthModel.fromFirebaseUser({User? user}) {
this.uid = user!.uid;
this.email = user.email;
this.displayName = user.displayName;
this.profilePic = user.photoURL;
}
}
The code for the service class is shown below:
class AuthService {
final FirebaseAuth authInstance = FirebaseAuth.instance;
final FirebaseFirestore firestoreInstance = FirebaseFirestore.instance;
Stream<UserAuthModel?> get currentUser => authInstance.authStateChanges().map(
(User? firebaseUser) => (firebaseUser != null) ? UserAuthModel.fromFirebaseUser(user: firebaseUser) : null,
);
}
The provider is defined as shown below:
return MultiProvider(
providers: [
Provider<AuthService>(
create: (_) => AuthService(),
),
],
This is how I'm trying to consume the provider within the code:
final authService = Provider.of<AuthService>(context);
final loggedInUser = authService.currentUser;
But when I try to access the user details using the currentUser
as shown below, I'm unable to do so, not sure why?
print(loggedInUser.uid);
print(loggedInUser.email);
print(loggedInUser.displayName);
print(loggedInUser.profilePic);
How can I access these details?
I don't see either the uid, email, displayName or profilePic
to select as shown in the pic below:
uid, email, displayName or profilePic
to select. Let me take a screenshot and attach it to the question for better clarity.