This is main file where stream builder is used
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: ‘Twitter Clone’,
theme: ThemeData(
useMaterial3: false,
),
themeMode: ThemeMode.system,
home: StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (ctx, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const loading();
}
if (snapshot.hasData) {
return const Homepage();
}
return const startingscreen();
},
),
);
}
}
When a user is not authenticated, the app navigates to the starting screen, then proceeds to the email screen, followed by the email verification screen, password screen, username screen, and so forth (by Navigator.Push). Once the user completes the authentication process and a new account is created, the home screen does not appear.
It’s strange to see that the login process works properly, navigating from the starting screen to the email screen, then to the password screen, and finally the homepage appears. However, in the case of a new user, the homepage does not appear.