The following NoSuchMethodError was thrown building StreamBuilder<QuerySnapshot>

Viewed 1717

I tried to implement a Streambuilder to my application, but I get an error when I try my code. This is the error I get:

The following NoSuchMethodError was thrown building StreamBuilder(dirty, state: _StreamBuilderBaseState<QuerySnapshot, AsyncSnapshot>#be008):
The getter 'documents' was called on null.
Receiver: null
Tried calling: documents

And this is the code I tried:

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test'),
      ),
      body: StreamBuilder(
        stream: Firestore.instance
            .collection('test')
            .document('OrRPMJJyPCThMYMi0mUl')
            .collection('test')
            .snapshots(),
        builder: (context, snapshot) {
          return ListView.builder(
            itemCount: snapshot.data.documents.length,
            itemBuilder: (context, index) {
              DocumentSnapshot reservation = snapshot.data.documents[index];
              return ListTile(
                title: Text(test['name']),
              );
            },
          );
        },
      ),
    );
2 Answers

The error indicates that snapshot returns null, make sure that the query is correct, It is likely that this part of your query is not correct document('OrRPMJJyPCThMYMi0mUl').

try documents instead of document.

Related