我使用Firebase身份验证,当我登录或注册时,它可以正常工作,并将我提升到主页,但是当我注销时,它成功注销了我
但是当我再次登录时,它停留在加载屏幕上
我的应用程序流程是:main-> Wrapper-> Authenticate-> Login / Register-> Home
这是包装器:
class _WrapperState extends State<Wrapper> {
int _currentTab = 1;
final _page = [
Search(),
Home(),
Account(),
];
@override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
print(user.uid);
if (user == null) {
return Authenticate();
} else {
return
// Home();
}
}
这是登录名:
RaisedButton(
color: Colors.green[400],
child: Text(
'دخول',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
if(_formKey.currentState.validate()){
setState(() => loading = true);
dynamic result = await _auth.signInWithEmailAndPassword(email, password);
if(result == null) {
setState(() {
loading = false;
error = 'Could not sign in with those credentials';
});
}
}
}
),
这是FirebasE的signIn方法实现:
Future signInWithEmailAndPassword(String email, String password) async {
try {
AuthResult result = await _auth.signInWithEmailAndPassword(email: email, password: password);
FirebaseUser user = result.user;
return user;
} catch (error) {
print(error.toString());
return null;
}
}
最佳答案
由于您有两个setState
,因此卡在加载中,每当您按下按钮时,第一个setState
就会被调用,并将true赋给变量loading
。您应该将其更改为以下内容:
onPressed: () async {
if(_formKey.currentState.validate()){
setState(()async{
loading = true;
dynamic result = await _auth.signInWithEmailAndPassword(email, password);
if(result == null) {
loading = false;
error = 'Could not sign in with those credentials';
});
}
}
}
关于firebase - Firebase:注销停留在加载后登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62122529/