I'm new to flutter and firebase so bear with me. I'm using email sign up with firestore and flutter on my app, on registration some additional fields are saved to firestore. I want to retrieve those fields to display on the user profile.
The key identifier for the fields saved to the users collection is the auto generated user id upon sign up.
I have in my widget build context
child: new FutureBuilder<FirebaseUser>(
future: _firebaseAuth.currentUser(),
builder: (BuildContext context, AsyncSnapshot<FirebaseUser> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
String userID = snapshot.data.uid;
_userDetails(userID);
return new Text(firstName);
}
else {
return new Text('Loading...');
}
},
),
And my get associated data method is:
Future<void> getData(userID) async {
// return await Firestore.instance.collection('users').document(userID).get();
DocumentSnapshot result = await Firestore.instance.collection('users').document(userID).get();
return result;
}
To retrieve the user details
void _userDetails(userID) async {
final userDetails = getData(userID);
setState(() {
firstName = userDetails.toString();
new Text(firstName);
});
}
I have tried adding a .then() to the set state in _userdetails but its saying userDetails is a type of void and cannot be assigned to string. The current code block here returns instance of 'Future' instead of the user Details.
Your method is marked as async
so you have to wait for the result :
Future<void> _userDetails(userID) async {
final userDetails = await getData(userID);
setState(() {
firstName = userDetails.toString();
new Text(firstName);
});
}
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