I am using a stream builder that reacts to the Firebase user state. I am in "Landing Screen", and I push "Login Screen" on top of it. After I log in, the Stream Builder replaces the "Landing Screen" with "Discover Screen" correctly. However, the pushed "Login Screen" remains on top of "Discover Screen".
How do I use Stream Builder to also replace the pushed widgets from Navigator?
Here is the code:
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final AuthService _authService = GetIt.I.get<AuthService>();
return Scaffold(
body: StreamBuilder(
stream: _authService.userStream,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const LoadingScreen();
} else if (snapshot.hasError) {
return const ErrorScreen();
} else if (snapshot.hasData) {
return const DiscoverScreen();
} else {
return const LandingScreen(); // I push the Login Screen inside this screen
}
},
),
);
}
}