sanjai m
sanjai m

Reputation: 11

Bad state: cannot get field "username" on a DocumentSnapshotPlatform which does not exist

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

Upvotes: 1

Views: 39

Answers (1)

sanjai m
sanjai m

Reputation: 11

i finally found out where did i made the mistake i made the mistake in the rules in firestore i didnt set the users authentication for writing so only it didnt shows any userid key to my messages .So only my userId and username Id is has a Difference once i changed it workds perfectly

Upvotes: 0

Related Questions