As part a my authentication service, I’m trying to map the Streamfrom the
firebase_authpackage to a realtime listener
Stream` of the corresponding user in firestore.
To achieve that, I’m using the switchMap
stream transformer from the rxDart
package.
However, the value returned from FirebaseAuth.instance.onAuthStateChanged
can be null
and in that case I would like the resulting stream to return null
as well.
Thing is, I’m not sure how to achieve that. Should I return an single value Stream of value null
? If so how?
I tried returning a generator function async* {yield null};
but it didn’t work.
_userStream = FirebaseAuth.instance.onAuthStateChanged
.transform(SwitchMapStreamTransformer((FirebaseUser user) {
// user can be null here what should I return ?
return () async* {yield null}; // this doesnt work
return FirestoreUserService.getUserStreamFromId(user.uid);
}));
Cheers! 🙂
@hoc081098 Thanks! Exactly what I needed 🙂
For the record, here is what my function ended looking like