Flutter 无法登录用户!火基/颤振
我是新来的飞和火基地! 正在尝试设置身份验证,但我的登录不起作用! 当应用程序启动时,用户可以看到主屏幕,我有两个按钮可以导航到登录和注册,注册可以完美地工作,并将用户重定向到新屏幕,而登录确实在(控制台)中说一切正常,但无法导航 这是我的授权服务:Flutter 无法登录用户!火基/颤振,flutter,google-cloud-firestore,firebase-authentication,Flutter,Google Cloud Firestore,Firebase Authentication,我是新来的飞和火基地! 正在尝试设置身份验证,但我的登录不起作用! 当应用程序启动时,用户可以看到主屏幕,我有两个按钮可以导航到登录和注册,注册可以完美地工作,并将用户重定向到新屏幕,而登录确实在(控制台)中说一切正常,但无法导航 这是我的授权服务: class AuthService { static final _auth = FirebaseAuth.instance; static final _firestore = Firestore.instance;
class AuthService {
static final _auth = FirebaseAuth.instance;
static final _firestore = Firestore.instance;
static void signUpUser(
BuildContext context, String name, String email, String password) async {
try {
AuthResult authResult = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
FirebaseUser signedInUser = authResult.user;
if (signedInUser != null) {
_firestore.collection('/users').document(signedInUser.uid).setData({
'name': name,
'email': email,
'profileImageUrl': '',
});
Provider.of<UserData>(context, listen: false).currentUserId =
signedInUser.uid;
Navigator.pushNamed(context, HomeScreen.id);
// Navigator.pop(context);
}
} catch (e) {
print(e);
}
}
static void login(String email, String password) async {
try {
await _auth.signInWithEmailAndPassword(email: email, password: password);
} catch (e) {
print(e);
}
}
static void logout() {
_auth.signOut();
}
}
您需要在登录方法中使用此选项
Navigator.pushNamed(context, YourLoginPageName.id);
您在控制台中遇到了什么异常?我可以看一下您的控制台屏幕截图吗?嘿,您忘记添加导航到主页代码
Navigator.pushNamed(context,HomeScreen.id)代码>我无法添加Navigator.pushName(上下文,YourLoginPageName.id);方法里面!我在上下文下得到红线,dart分析显示未定义的名称上下文!我尝试通过_submit()导航,但即使用户不存在,它也会导航!感谢各位,btwim无法添加Navigator.pushName(上下文,YourLoginPageName.id);方法里面!我在上下文下得到红线,dart分析显示未定义的名称上下文!只需像在注册方法中那样将上下文传递给登录。
_submit() {
if(_formKey.currentState.validate()){
_formKey.currentState.save();
AuthService.login(_email, _password);
}
}
Navigator.pushNamed(context, YourLoginPageName.id);