I have been trying to get a document data from /users collections,
but the problem is that after I declare de builder:
which is a required parameter for FutureBuiulder, the data is not passing it and I get data = null.
what am I doing wrong?
future: FirebaseFirestore.instance
.collection('users')
.doc(uid)
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
print('The Documents Exists');
print(documentSnapshot.data());
}
else {
print('The document Do not Exist');
}
} //here closes then((DocumentSnapshot documentSnapshot) {
),// here closesthen((DocumentSnapshot documentSnapshot)
I get the document right as you can see below on the img
However, the data is not passing after the builder:
builder: (context, documentSnapshot) {
if (documentSnapshot.hasData) {
print('The Documents Exists');
print(documentSnapshot.data());
}
else {
print('The document Do not Exist');
}
EDIT
Here is my full code:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
class NewHome extends StatefulWidget {
@override
_NewHomeState createState() => _NewHomeState();
}
class _NewHomeState extends State<NewHome> {
FirebaseFirestore firestore = FirebaseFirestore.instance;
FirebaseAuth auth = FirebaseAuth.instance;
@override
Widget build(BuildContext context) {
final User user = auth.currentUser;
final uid = user.uid;
return new Scaffold(
body: new Container(
child: FutureBuilder(
future: FirebaseFirestore.instance
.collection('users')
.doc('uid')
.get(),
builder: (context, snapshot) {
DocumentSnapshot manuais =
snapshot.data;
if (snapshot.hasData) {
print('okkk');
}
else{
print('nopeeeee');
}
return Container(
padding: EdgeInsets.all(16),
child: ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, uid) {
return Card(
color: Colors.grey[250],
child: Container(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
new Image.asset(
'Images/pdflogo.png',
width: 32,
),
Center(
child: Text(
(snapshot
.data()['nome']
.toString()),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 16),
),
),
])));
}));
})));
}
}
