firestore data not displaying in Flutter listtile ListView

Viewed 193

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)

1 Answers
Related