type 'Query' is not a subtype of type 'Stream<QuerySnapshot>?'

Viewed 313

in Flutter, I have collection called vendors and I am going to get collection base on the image of its collection

here is my code:

class _TopPickStoreState extends State<TopPickStore>{
StoreService _storeServices = StoreService();
@override
Widget build(BuildContext context){
   return Container(
   child: StreamBuilder<QuerySnapshot>(
     stream: _storeServices.getTopPickedStore(),
     builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapShot){
      if(!snapShot.hasData)return CircularProgressIndicator();
      return Column(
        children: [
          Flexible(
              child: ListView(
                scrollDirection: Axis.horizontal,
                children: snapShot.data.docs.map((DocumentSnapshot document){
                  return Container(
                    width: 80,
                    child: Column(
                      children: [
                        Image.network(document['imageUrl']),
                      ]
                    ),
                  )
                ;}).toList(),
              ),
          )
        ],
      );
    }
    ),
);

} }

this is the function to get the collection:

import 'package:cloud_firestore/cloud_firestore.dart';


 class StoreService{
     getTopPickedStore(){
       return FirebaseFirestore.instance.collection('vendors')
       .where('accVerified', isEqualTo:true)
       .where('isTopPicked',isEqualTo: true)
       .orderBy('shopName');
     }
   }

and i got this error message:

type 'Query' is not a subtype of type 'Stream<QuerySnapshot ?'

can anyone help me to solve this?

1 Answers

Change it to this:

getTopPickedStore() async {
       return await FirebaseFirestore.instance.collection('vendors')
       .where('accVerified', isEqualTo:true)
       .where('isTopPicked',isEqualTo: true)
       .orderBy('shopName').snapshots();

You need to use snapshots to change it into a querysnapshot.

Related