【发布时间】:2021-05-09 09:39:06
【问题描述】:
根据用户是否成功通过身份验证,我正在尝试转到主屏幕或停留在身份验证屏幕上。使用 Firebase 身份验证的 authStateChanges 和流构建器。
我没有收到错误代码,控制台显示
D/FirebaseAuth(21665): Notifying id token listeners about user ( pG6pORODSGMi21fuaoql29hqXZp2 ).
D/FirebaseAuth(21665): Notifying auth state listeners about user ( pG6pORODSGMi21fuaoql29hqXZp2 ).
所以身份验证成功,当我热启动应用程序时,它会进入主屏幕并显示应有的信息。 这是代码
FutureBuilder(
future: _initialization,
builder: (context, appsnapShot) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
routes: {
SignupScreen.routeName: (ctx) => SignupScreen(),
AuthScreen.routeName: (ctx) => AuthScreen(),
HomeScreen.routeName: (ctx) => HomeScreen(),
UserPhoneAdds.routeName: (ctx) => UserPhoneAdds(),
PhoneAddForm.routeName: (ctx) => PhoneAddForm(),
EditPhoneScreen.routeName: (ctx) => EditPhoneScreen(),
},
home: appsnapShot.connectionState != ConnectionState.done
? SplashScreen()
: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return SplashScreen();
}
if (snapshot.hasData) {
return HomeScreen();
} else {
return AuthScreen();
}
},
),
);
});
仅供参考-这不在课程范围内,并且在来自此的应用程序中正常工作 感谢您的帮助。
【问题讨论】:
标签: firebase flutter dart firebase-authentication