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;
And for getting the UID:
final FirebaseUser user = auth.currentUser().then((FirebaseUser user) {
final userid = user.uid;
});
This but I keep getting the error
Undefined name 'auth'.
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;
Now you can use stuff like auth.currentUser().then(...) like you are doing correctly.
Undefined name 'FirebaseAuth', and not importing library firebase_auth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With