Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
flatterfirebaseauth:我如何检查用户是否在空白中登录?_Firebase_Flutter_Firebase Authentication - Fatal编程技术网

flatterfirebaseauth:我如何检查用户是否在空白中登录?

flatterfirebaseauth:我如何检查用户是否在空白中登录?,firebase,flutter,firebase-authentication,Firebase,Flutter,Firebase Authentication,我是FirebaseAuth的新手,我想在一个空白中检查用户是否登录,如果不是,他将被重定向 这就是我的空虚: void newEntry() { showDialog<AlertDialog>( context: context, builder: (BuildContext context) { return neuerEintrag(addItem); }); } void newEntry(

我是FirebaseAuth的新手,我想在一个空白中检查用户是否登录,如果不是,他将被重定向

这就是我的空虚:

  void newEntry() {
    showDialog<AlertDialog>(
        context: context,
        builder: (BuildContext context) {
          return neuerEintrag(addItem);
        });
  }
void newEntry(){
显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
返回neuerEintrag(附加项);
});
}
这是我的检查,如果用户os LoggedIn在另一个类中:

    class loginProfile extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final AuthService auth = Provider.of(context).auth;
    return StreamBuilder<String>(
      stream: auth.onAuthStateChanged,
      builder: (context, AsyncSnapshot<String> snapshot) {
        if (snapshot.connectionState == ConnectionState.active) {
          final bool signedIn = snapshot.hasData;
          return signedIn ? Profil() : FirstView();
        }
        return CircularProgressIndicator();
      },
    );
  }
}
类登录配置文件扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
final AuthService auth=Provider.of(context.auth);
返回流生成器(
流:auth.onAuthStateChanged,
生成器:(上下文,异步快照){
if(snapshot.connectionState==connectionState.active){
最终bool signedIn=snapshot.hasData;
返回签名为?profile():FirstView();
}
返回循环ProgressIndicator();
},
);
}
}

谢谢

也许使用
currentUser
同步getter就足够了

if (FirebaseAuth.instance.currentUser != null) {...}

ref:

也许使用
currentUser
同步getter就足够了

if (FirebaseAuth.instance.currentUser != null) {...}
参考: