type 'Query' is not a subtype of type 'Stream<QuerySnapshot>?'
248
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.
Author by
ryan chandra
Updated on December 29, 2022Comments
-
ryan chandra over 1 year
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?
-
Huthaifa Muayyad about 3 yearsThe problem is being caused by
getTopPickedStore()
, post this function. Because it's returningquery
object, but your streambuilder is querysnapshot. Decide which one of them you want to use, then it can be fixed -
ryan chandra about 3 yearsi have put the getTopPickedStore() function, i hope you can explain more to me how to solve the problem. thank you very much
-
Huthaifa Muayyad about 3 yearsI added an answer. Basically what's written currently in the function is a query. Meaning it's a set of instructions to tell Firebase where and what to look for, but you don't tell it what to do afterwards. It has to be told to
get()
orsnapshots()
, to actually go to firebase, and get those documents, and then return them as a querysnapshot.
-