Search code examples
firebaseflutterdartgoogle-cloud-firestorestream-builder

Flutter SteamBuilder throwing error on first argument context


I have a problem here with flutter (v2.8.1) on my windows.

I am trying to use StreamBuilder class to fetch data from firebase but it is not working anyhow. I tried to use BuildContext context but it is still throwing me error on context.

Please have a look at my code and let me know what I am doing wrong. Answers are appreciated. Thanks in advance.

StreamBuilder(builder: (BuildContext context, snapshot), stream: _firestore.collection('messages').snapshots()),

Error :

The argument type 'Type' can't be assigned to the parameter type 'Widget Function(BuildContext, AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>)'.

Please check the image : https://i.sstatic.net/wqUfc.jpg


Solution

  • The builder argument should be a function that returns a widget.

    builder: (context, snapshot) {
      // return a widget that uses the snapshot
      // for example
      return Text(snapshot.data().title);
    }