Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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
在代码中随处使用FireBase uid-颤振_Firebase_Flutter_Firebase Authentication - Fatal编程技术网

在代码中随处使用FireBase uid-颤振

在代码中随处使用FireBase uid-颤振,firebase,flutter,firebase-authentication,Firebase,Flutter,Firebase Authentication,当我需要的时候,我试图在代码中的任何地方使用登录用户的uid,但我找不到一种方法来使用它。我可以登录、注销、更新记录等。但是如果我想在另一个dart文件上使用uid,我就不能这样做 最好我想在常量文件中添加uid,这样我就可以方便地在任何需要的地方访问它 FirebaseAuth auth = FirebaseAuth.instance; String uid = ''; auth.currentUser().then((val){ setState(() { this.uid= v

当我需要的时候,我试图在代码中的任何地方使用登录用户的uid,但我找不到一种方法来使用它。我可以登录、注销、更新记录等。但是如果我想在另一个dart文件上使用uid,我就不能这样做

最好我想在常量文件中添加uid,这样我就可以方便地在任何需要的地方访问它

FirebaseAuth auth = FirebaseAuth.instance;
 String uid = '';

auth.currentUser().then((val){
  setState(() {
  this.uid= val.uid; 
   print("UID: $uid");
  });
}).catchError((e){
print("error:$e");
});
在initState中使用FirebaseAuth类的currentUser方法。它将为您提供当前用户uid