I'm new to Firebase and I managed to finish authentication in my flutter app using Firebase as cloud database and it works perfectly fine. But how do I get the current user data? My situation/problem goes something like this.
- User A logged in and get username A(their name)
- User B logged in and still get username A(User A name)
the situation is like I logged in Facebook but I entered someone else's profile because I read the same collection and document. This is my code of how it goes
CollectionReference users = FirebaseFirestore.instance.collection('Harris');
return FutureBuilder<DocumentSnapshot>(
future: users.doc('username').get(),
builder: (BuildContext context,
AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
return Center(child: Text("Something went wrong"));
}
if (snapshot.hasData && !snapshot.data!.exists) {
return Center(child: Text("Document does not exist"));
}
if (snapshot.connectionState == ConnectionState.done) {
Map<String, dynamic> data =
snapshot.data!.data() as Map<String, dynamic>;
return Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
color: brightGray,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Welcome,',
style: ktextFont3,
),
Text(
'${data['username']}',
style: ktextFont4,
),]));}
return Center(
child: CircularProgressIndicator(
color: mintGreen,
));
},
);
this is my Firebase Console

I have tried to replace the collection and document with username variable but it shows null when I hot restart the app. Any advice/assist is appreciated. Thank you