简体   繁体   English

根据闭包上下文的要求,返回类型“LoginPage”不是“void”

[英]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所以,如果用户是 null .. 页面移动到登录页面

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

          }
        });
    }

Add an else block添加一个 else 块

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());

} }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据闭包上下文的要求,返回类型“Transaction”不是“Future&lt;_&gt;” - The return type 'Transaction' isn't a 'Future<_>', as required by the closure's context 错误:返回类型'Iterable<book> ' 不是 ' 列表<book> ',根据闭包上下文的要求。 在 Flutter</book></book> - error: The return type 'Iterable<Book>' isn't a 'List<Book>', as required by the closure's context. in Flutter Flutter Firestore Stream 错误“根据闭包上下文的要求”。 - Flutter Firestore Stream error "as required by the closure's context." 无法在当前上下文中推断闭包类型 - Unable to infer closure type in the current context 错误:无法将“CueCardModel”类型的值转换为闭包结果类型“Void”SwiftUI - Error: Cannot Convert Value of Type “CueCardModel” to Closure Result Type “Void” SwiftUI 无法从具有无效结果类型的方法返回值 - Cannot return value from a method with void result type 为什么不回来<Redirect to="/" />跑步? - why isn't return <Redirect to="/" /> running? 参数类型 &#39;Future<void> Function(FirebaseUser)&#39; 不能分配给参数类型 &#39;void Function(User)&#39; - The argument type 'Future<void> Function(FirebaseUser)' can't be assigned to the parameter type 'void Function(User)' 错误:未为类型“DocumentSnapshot”定义运算符“[]” - error: The operator '[]' isn't defined for the type 'DocumentSnapshot' 未为“FirebaseAppCheck”类型定义方法“getInstance” - The method 'getInstance' isn't defined for the type 'FirebaseAppCheck'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM