I am trying to create a stream of my user modal based on the authenticate services of fire base.
create user object base on FirebaseUser:
UnicoUser? _userFromFirebaseUser(User? user){ if (user != null) { UnicoUser? _unicoUser; DatabaseService(uid: user.uid).getUserFromUserId().then((value){ _unicoUser = value; print("user id: "+ value.uid);}); return _unicoUser; } return null; } create the auth change user stream:
Stream<UnicoUser?> get unicoUser { return _auth.authStateChanges().map(_userFromFirebaseUser); } the implement in the widget:
StreamBuilder( stream: AuthServices().unicoUser, builder: (context, AsyncSnapshot<UnicoUser?> snapshot) { if (snapshot.connectionState == ConnectionState.waiting){ return const Loading();} else if(snapshot.hasData ){ return LoggedInWrapper(currentUser: snapshot.data!,);} else if (snapshot.hasError){ return const Center(child: Text("Something went wrong"),);} else { print("snapshot is: "+ snapshot.data.toString());return const Authenticate();} }, ) even if the user is authenticated and the unicouser object is not null the snapshot data is null.. output:
Performing hot reload... Syncing files to device AOSP on IA Emulator... Reloaded 0 libraries in 111ms. I/flutter (22920): snapshot is: null I/flutter (22920): user id: fnWyLWrCznQDSmZGr6kShpXSsK52