FutureBuilder(
future:Future.value( FirebaseFirestore.instance.collection(‘users’).doc(userId).get(),),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Text(“Loading…”);
} else if (snapshot.hasError || snapshot.data == null) {
return const Text(“User not found”);
}
// Safely access the 'username' field
var username = snapshot.data?['username'];
if (username!= null && username.isNotEmpty) {
return Text(
username, // Display the username
style: const TextStyle(fontWeight: FontWeight.bold),
);
} else {
return const Text("Username not found");
}
},
),
Bad state: cannot get field “username” on a DocumentSnapshotPlatform which does not exist
New contributor
sanjai m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.