Cannot get list of data from cloud firestore


I am wanting to get the list of data from the cloud firestore. I have setup everything. With the following code, i am just able to get one data instead of all the list. And I am getting the following error :
Bad state: field does not exist within the DocumentSnapshotPlatform

 class HomePage extends StatefulWidget {
      static const routeName = 'homePage';
      _HomePageState createState() => _HomePageState();
    class _HomePageState extends State<HomePage> {
      late String id;
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text("Latest"),
          body: StreamBuilder<QuerySnapshot>(
            stream: FirebaseFirestore.instance.collection("latest").orderBy('number',descending: true).snapshots(),
            builder: (context, snapshot) {
              return !snapshot.hasData
                  ? Center(child: CircularProgressIndicator())
                  : ListView.builder(
                itemBuilder: (context, index) {
                  DocumentSnapshot data =!.docs[index];
                  return  Stack(
                    alignment: Alignment.topCenter,
                    fit: StackFit.loose,
                    clipBehavior: Clip.hardEdge,
                    children: [
                        child: Container(
                            height: 200,
                            width: MediaQuery.of(context).size.width,
                            child: Card(
                              child: Center(
                                  child: Row(
                                      children: [
                                          textAlign: TextAlign.start,
                                          style: const TextStyle(
                                            color: Colors.indigo,
                                            fontWeight: FontWeight.bold,
                        onTap: () {
                    //   ),


I think you should check the document fields name and also make sure all the fields exist in all documents.

Answered By – AFRIDI

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published