0

I tried to retrieve two collections of data from firebase to screen as a list in Flutter app.But it shows error "Bad state: field does not exist within the DocumentSnapshotPlatform". I don't know how to fix it. Can anyone help me how to solve it? Thank you!! here is my code

final CollectionReference _addExpense= FirebaseFirestore.instance.collection('add_expense');
final CollectionReference _addincome= FirebaseFirestore.instance.collection('add_income');

i tried it for two collection tables to retrieve the data.

Expanded(
   flex: 4,
   child: StreamBuilder(
stream: _addExpense.snapshots(),
    builder: (context, snapshot1) {
      return StreamBuilder(
        stream: _addincome.snapshots(),
        builder: (context, snapshot2) {
          if (!snapshot2.hasData) return const Text('Loading...');
          if (!snapshot1.hasData) return const Text('Loading...');
          return ListView.builder(
           scrollDirection: Axis.vertical,
            shrinkWrap: true,
            physics: ScrollPhysics(),
           // itemExtent: 550.0,
            itemCount: snapshot2.data!.docs.length,
            itemBuilder: (BuildContext context, index) {
              final DocumentSnapshot documentSnapshot = snapshot2.data!.docs[index];
              final DocumentSnapshot documentSnapshot1 = snapshot1.data!.docs[index];
              return Column(

Card(
  child: ListTile(
    subtitle: Row(
      children: <Widget>[
        Container(
          width: 75,
          child: Text(
            "${documentSnapshot.get('dates')}"//['dates']}"
                "\n${documentSnapshot.get('times')}"//['times']}"
                "\n${documentSnapshot.get('payment')}"//['payment']}"
                "\n${documentSnapshot.get('notes')}"//['notes']}"
          ),
        ),

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84

1 Answers1

0

This occurs when the document you're trying to read doesn't contain all the fields you are trying to read.