0
I’m using Flutter to create a mobile app with two collections in the Cloud Firestore, the collection user
and the collection person
.
- The collection
person
stores the information of all persons who can register in the app. - The collection
user
stores the date of the registered user.
I want to use the information inside the collection documents user
to search for a document in the collection person
. After the user registers I cannot use the user name to perform a query in the collection person
.
Future<String> getPersonName(userId) {
Firestore.instance
.collection('user')
.document(userId)
.get()
.then((DocumentSnapshot ds) {
return ds['Person Name'];
}, onError: (error) {
return error;
}
);
}
Future<String> getPersonData(personName, documentData) async {
DocumentSnapshot snapshot = await Firestore.instance
.collection('person')
.document(userId)
.get();
var name= snapshot.data[documentData];
if (name is String) {
return name;
} else {
return 'Empty';
}
}
The function getPersonName()
returns a Future with the value I want to use in the function getPersonData()
In my Scaffold
I used a FutureBuilder
to display the date.
FutureBuilder(
future: getPersonData(personName, 'Data'),
builder: (context, snapshot) {
return Text(snapshot.data);
}),
The Future returns the correct information
In the FutureBuilder
how can I access the value of personName
? I’ve tried several options and I always end up with a Future instead of the value.
Where is the line you call the function
getPersonName()
?– Naslausky
You seem to be new on the site... So a tip, don’t pollute the same with multiple questions, you could just EDIT your other question here!
– Matheus Ribeiro