Firebase:注销后登录在加载时卡住

Firebase:注销后登录在加载时卡住,firebase,flutter,authentication,dart,firebase-authentication,Firebase,Flutter,Authentication,Dart,Firebase Authentication,我使用Firebase身份验证,当我登录或注册时,它可以正常工作并将我推进主页,但当我注销时,它会将我成功注销 但当我再次登录时,它卡在加载屏幕上 我的应用程序流程是:main->Wrapper->Authenticate->Login/Register->Home 这是包装纸: class _WrapperState extends State<Wrapper> { int _currentTab = 1; final _page = [ Search(),

我使用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();
       }
}
下面是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。您应该将其更改为以下内容:

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';
                      });
                    }
                  }
                }

我修改了它作为您的更正,但现在什么也没有发生,它甚至没有进入加载屏幕我删除了加载,并在控制台中通知我它已登录,但是导航的问题是它没有进入主页。你有在构建方法中加载的条件吗?在我获得uid后,Authenticate用uid导航到包装器,然后包装器进入主页。我删除了所有加载代码,直到用户可以轻松注销并再次登录
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';
                      });
                    }
                  }
                }