简体   繁体   中英

The return type 'LoginPage' isn't a 'void', as required by the closure's context

so, if user is null.. page is move into login page

  Widget build(BuildContext context) {
        AuthServices.userStream.listen((User? user) {
          if (user == null) {
            return LoginPage(); 

          }
        });
    }

Add an else block

else{
   //when user is not null 
   retun yourPage();
 }

Complete code:-

  Widget build(BuildContext context) {
    AuthServices.userStream.listen((User? user) {
      if (user == null) {
        return LoginPage(); 
      }
    else{
   //when user is not null 
    retun yourPage();
     }
    });
 }
AuthServices.userStream.listen((User? user) {
  if (user == null) {
    return login();
  }
});
enter code here

then in login()

void login() {
Get.to(LoginPage());

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM