anishdsk
anishdsk

Reputation: 101

Recieving a RangeError message when reading data from Firestore using Flutter

I am trying to retrieve data from the first document from a collection on firestore. But, I keep getting the following error: "RangeError (index): Invalid Value: Valid Value Range is Empty: 0"

    body: StreamBuilder(
      stream: Firestore.instance.collection('users').snapshots(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) return Text('Loading Data...');
        return Column(
          children: <Widget>[
            Text(snapshot.data.documents[0]['email']),
          ],
        );
      },
    ),

Upvotes: 0

Views: 113

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80952

Try adding the code inside the else:

if (!snapshot.hasData) return Text('Loading Data...');
else{
        return Column(
          children: <Widget>[
            Text(snapshot.data.documents[0]['email']),
          ],
        );
     }
   return Text("no Data");
      },

Upvotes: 2

Related Questions