Flutter Provider: Provide 2 streams with one dependent on the other
The solution is to save the second stream (loggedInUserStream) in the state and change it whenever the first stream (authenticationStream) emits a new value (by listening to it) like in the code below:
class _FloatState extends State<Float> { StreamSubscription<FirebaseUser> authenticationStreamSubscription; Stream<User> loggedInUserStream; StreamSubscription<FirebaseUser> setLoggedInUserStream() { authenticationStreamSubscription = FirebaseConnection.getAuthenticationStream().listen((firebaseUser) { loggedInUserStream = FirebaseConnection.getUserStream(uid: firebaseUser?.uid); }); } @override void initState() { super.initState(); authenticationStreamSubscription = setLoggedInUserStream(); } @override void dispose() { super.dispose(); authenticationStreamSubscription.cancel(); } @override Widget build(BuildContext context) { return StreamProvider<User>.value( value: loggedInUserStream, child: MaterialApp( debugShowCheckedModeBanner: false, initialRoute: LoginScreen.id, onGenerateRoute: RouteGenerator.generateRoute, ), ); }}
I only needed the first stream (authenticationStream) to get the second one (loggedInUserStream) so I didn't provide it to the widgets below.