spervez
spervez

Reputation: 33

Firestore ConnectionState is "ConnectionState.waiting"

This appears to be an issue that has been answered before (e.g. by @MSaudi here). I followed that discussion but it did not solve the problem I am running into. Would appreciate some pointers as I am very much a beginner to flutter/firestore. I am simply following an online tutorial I found just to get myself acquainted with the basics. Its been going well up to this point.

Widget _buildUserList() {
    return StreamBuilder(
      stream: _chatService.getUsersStream(), 
      builder: (context, snapshot) {
        // error
        if (snapshot.hasError) {
          return const Text("Error");
        }

        // loading..
        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Text("Loading...");
        }

        // return list view
        return ListView (
          children: snapshot.data!
            .map<Widget>((userData) => _buildUserListItem(userData, context))
            .toList(),
        );
      },
    );
  }

  Widget _buildUserListItem(Map<String, dynamic> userData, BuildContext context) {
    // display all users except current user

    return UserTile(
      text: userData["email"],
      onTap: () {
        Navigator.push(context, MaterialPageRoute(builder: (context) => ChatPage(
          receiverEmail: userData["email"],
          )));
      },
    );
  }

Firebase rules

Android Emulator output

Something obvious I am missing maybe?

Adding code for getUsersStream as requested by @pskink

  Stream<List<Map<String,dynamic>>> getUsersStream() {
    return _firestore.collection("Users").snapshots().map((snapshot) {
      return snapshot.docs.map((doc) {
        final user = doc.data();
        return user;
      }).toList();
    });
  }

Upvotes: 0

Views: 55

Answers (0)

Related Questions