Firebase身份验证错误:未定义名称"auth" [英] Firebase authentication error: Undefined name 'auth'
本文介绍了Firebase身份验证错误:未定义名称"auth"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用每个用户的UID来访问我的firestore数据库,例如:
I would like to acces my firestore databse, by using the UID of each user, like so:
return new StreamBuilder(
stream: Firestore.instance.collection('users').document(uid).snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return new Text("Loading");
}
var userDocument = snapshot.data;
并获取UID:
final FirebaseUser user = auth.currentUser().then((FirebaseUser user) {
final userid = user.uid;
});
这但我不断收到错误消息
This but I keep getting the error
Undefined name 'auth'.
推荐答案
要在Flutter中使用 FirebaseAuth
,您必须获得对此实例的引用.每当需要使用Firebase身份验证时,将此行添加到小部件/文件的顶部:
To use FirebaseAuth
in flutter, you must get a reference to such instance. Add this line at the top of your widget/file whenever you need to use Firebase Authentication:
import 'package:firebase_auth/firebase_auth.dart';
FirebaseAuth auth = FirebaseAuth.instance;
现在,您可以像正确执行操作一样使用 auth.currentUser().then(...)
之类的东西.
Now you can use stuff like auth.currentUser().then(...)
like you are doing correctly.
这篇关于Firebase身份验证错误:未定义名称"auth"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文