Hello! I'm trying to get the 'username' of the current user from the
users database on Firestore. I only need to get it once (NO need for streambuilder, futurebuilder, etc). I only need the 'username' to make it appear on the UI 1 time and it will not change depending on the activity, meaning that once I get the 'username' from the database, it will always stay the same. I'm currently using the code below, BUT I think I'm overcomplicating myself. Also, if I use the code below, I have a problem because I have a future String that I want to place in a String variable (so it is not letting me use it). What is a more simple way to get the 'username' 1 time from the
users database? Thanks
Future<String> getCurrentUserData() async{
final String userId = user.uid;
DocumentSnapshot snapshot = await FirebaseFirestore.instance.collection('users').doc(userId).get();
return currentUsername = snapshot['username'];
}