I am retrieving a user's first name from firestore, store it in a variable and then trying to display it using a Text Widget. The database query works for sure because I print it's outcome. On the other hand, the variable used to store the data is used in the Text widget but it's not displaying anything.
homepage.dart
//get the specific document I need
DocumentReference userName = FirebaseFirestore.instance
.collection('users')
.doc(FirebaseAuth.instance.currentUser!.uid);
//Variable used to store the name
String firstName = '';
@override
Widget build(BuildContext context) {
//Get specific field from a document
userName.get().then((DocumentSnapshot ds) {
firstName = ds['firstName'];
print(firstName);
});
return Scaffold(
appBar: AppBar(
title: const Text('Homepage'),
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.only(
top: 20,
),
child: Text(firstName)),
