Search code examples
firebaseflutterdartgoogle-cloud-firestoreflutter-futurebuilder

FLutter : cant complete retrieving data from firestore


i try to passing query from first page to second page within constructor

 Navigator.push(context, MaterialPageRoute(builder: (context) => ListWisataScreen(querySnapshot: dataService.getAllWisata(),)))

the query passed successfully and the data is showed up but is just half of them and the other data get following eror

Bad state: field does not exist within the DocumentSnapshotPlatform

here is the error screenshoot

here is secondpage code

FutureBuilder<QuerySnapshot>(
        future: querySnapshot,
        builder: (context, snapshot) {
          if(!snapshot.hasData || snapshot.connectionState == ConnectionState.waiting) {
            return Center(child: CircularProgressIndicator(strokeWidth: 3,),);
          } else if(snapshot.connectionState == ConnectionState.done && snapshot.hasData){
            return ListView.builder(
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                itemCount: snapshot.data.docs.length,
                itemBuilder: (context, index) {
                  var doc = snapshot.data.docs[index];
                  return ListTile(...);
                }
            );
          } else if(snapshot.connectionState == ConnectionState.none) {
            return Text("Tidak Ada Data");
          } else {
            return Text("Cek Koneksi Internet");
          }
        }
    )

Solution

  • Your error is in your own data in Firestore...

    Look again at your 5th document, you will see it is missing a field or a field is not properly filled-in... Most likely a typo..