stateChanges static method
Future<Widget>
stateChanges({
- Widget? loadingScreen()?,
- required Widget homeScreen(
- BuildContext,
- User
- required Widget loginScreen(),
Implementation
static Future<Widget> stateChanges({
Widget? Function(BuildContext)? loadingScreen,
required Widget Function(BuildContext, User) homeScreen,
required Widget Function(BuildContext) loginScreen,
}) async {
return StreamBuilder(
stream: fire.authStateChanges(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return loadingScreen!(context) ??
Scaffold(
body: Center(
child: SizedBox(
height: 100,
width: 100,
child: CircularProgressIndicator(),
),
),
);
}
if (snapshot.hasData) {
User user = fire.currentUser!;
return homeScreen(context, user);
}
return loginScreen(context);
},
);
}