'firestore data not displaying in Flutter listtile ListView

data from the firestore are not displaying in the list tile, all functions before the ListView are working fine such as the if statement for showing loading text, but when it reaches ListView nothing happens. I'm a little bit new to firebase. any help would be appreciated.

class _DoctorsState extends State<Doctors> {
  final Stream<QuerySnapshot> _userStream = 
  FirebaseFirestore.instance.collection('doctors').snapshots();

  @override
  Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Doctors'),
      backgroundColor: Colors.orange,
    ),
    body: SafeArea(
      child: StreamBuilder<QuerySnapshot>(
        stream: _userStream,
        builder:
            (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          
          if (snapshot.hasError) {
            return Text('Something went wrong');
          }

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

          return ListView(
            children: snapshot.data!.docs.map((DocumentSnapshot document) {
              Map<String, dynamic> doctors =
                  document.data()! as Map<String, dynamic>;
              return Padding(
                padding: EdgeInsets.all(5),
                child: Column(
                  children: [
                    SizedBox(
                      height: 10,
                    ),
                    Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(20)),
                          border: Border.all(color: Colors.grey)),
                      child: ListTile(
                          title: Text(doctors['name']),
                          subtitle: Text(doctors['speciality'])),
                    ),
                  ],
                ),
              );
            }).toList(),
          );
        },
      ),
    ),
  );
  }
}

The firestore collection I'm trying to display:

the firestore collection I'm trying to display

app shows a blank page (I'm displaying the application from web the converting it mobile view)



Solution 1:[1]

Did you read about indexing in firestore: https://firebase.google.com/docs/firestore/query-data/indexing

I think you should add index for your query. to make sure the problem what is,look at the log.you will find a helpful link that will allow you to easily make the index.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mohamed Amin