0

I am trying to make a search bar that can query my firestore DB and return results.

I have a stream builder that looks like this:

StreamBuilder(
        //query to firestore db
        stream:  streamQuery,
        //builds widget for loading and compleation
        builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {...

Which throws this error:

Couldn't infer type parameter 'T'.

Tried to infer 'dynamic' for 'T' which doesn't work:
  Parameter 'builder' declared as     'Widget Function(BuildContext, AsyncSnapshot<T>)'
                      but argument is 'Widget Function(BuildContext, AsyncSnapshot<QuerySnapshot<Object?>>)'.
The type 'dynamic' was inferred from:
  Parameter 'stream' declared as     'Stream<T>?'
                     but argument is 'Stream<dynamic>'.

Consider passing explicit type argument(s) to the generic.

What is odd is that if I replace the stream: with this:

db
        .collection('GearLockerItems')
        .where('itemName', isGreaterThanOrEqualTo: searchKey)
        .where('itemName', isLessThan: '${searchKey}z')
        .where('communityShare', isEqualTo: true)
        .where('reviewed', isEqualTo: true)
        .snapshots();

then it works. Having that firestore stream saved to a variable breaks things. FOr reference I am trying to follow this Stack Overflow questions:

https://stackoverflow.com/a/60873879/522607

Ten Digit Grid
  • 1,315
  • 4
  • 22
  • 43
  • Your StreamBuilder takes a type argument which you are not providing, so Dart has to infer the type, and sometimes gets that wrong. – Randal Schwartz Sep 15 '22 at 03:22

1 Answers1

0

I had to Add StreamBuilder<dynamic> to the Stream Builder:

body: StreamBuilder<dynamic>(
        stream: streamQuery,
        builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {...
Ten Digit Grid
  • 1,315
  • 4
  • 22
  • 43