get data in StreamBuilder from firestore

I have a stream and want to get data from it,if I try to display the data in a ListTile then I get to load only 2 values out of 4. If I use listView, the data is not loaded at all

Below I wrote 2 ways I tried to display the data, but I get to display everything you need without errors

1 method:  
Widget _carList() {
    if (customers != null) {
      return StreamBuilder(
        stream: customers,
        builder: (context, snapshot) {
          if (snapshot.data != null) {
            return ListView.builder(
              itemCount: snapshot.data.documents.length,
              padding: EdgeInsets.all(5.0),
              itemBuilder: (context, i) {
                return new ListTile(
                  title: Text(snapshot.data.documents[i].data['pickedDay']),
                  subtitle: Text(snapshot.data.documents[i].data['pickedTime']),
                  onTap: () {
                    updateDialog(
                        context, snapshot.data.documents[i].documentID);
                  },
                  onLongPress: () {
                    crudObj.deleteData(snapshot.data.documents[i].documentID);
                  },
                );
              },
            );
          }
        },
      );
    } else {
      return Text('Loading, Please wait..');
    }
  }   


This is the data i get with firestore                   
'pickedDay': this.pickedDay,
'pickedTime': this.pickedTime,
'service': this.service,
'phoneNumber': this.phoneNumber
UPDATE:  i wrote another one option:
2 method: ListTile(
                  title: Column(children: <Widget>[Text(snapshot.data.documents[i].data['pickedDay']),
                  Text(snapshot.data.documents[i].data['pickedTime'])],),
                  subtitle: Column(children: <Widget>[Text(snapshot.data.documents[i].data['service']),
                  Text(snapshot.data.documents[i].data['phoneNumber'])],),
                );
but it display only 2 notes out of 4
[enter image description here][1]
how do I display everything normally?


  [1]: https://i.stack.imgur.com/vmUIJ.png

1 answer

  • answered 2019-06-17 14:46 Megadec

    Check for null values in your records.

    return new ListTile(
                          title: snapshot.data.documents[i].data['pickedDay'] == null ? 
                          Text('No Data') : 
                          Text(snapshot.data.documents[i].data['pickedDay'])
    ...}