简体   繁体   English

制作流构建器 stream:一个变量会破坏 stream 构建器

[英]Making the streambuilder stream: a variable breaks stream builder

I am trying to make a search bar that can query my firestore DB and return results.我正在尝试制作一个可以查询我的 firestore 数据库并返回结果的搜索栏。

I have a stream builder that looks like this:我有一个看起来像这样的 stream 构建器:

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'.无法推断类型参数“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:奇怪的是,如果我用这个替换stream:

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.将该firestore stream 保存到变量中会破坏事情。 FOr reference I am trying to follow this Stack Overflow questions:作为参考,我正在尝试关注这个 Stack Overflow 问题:

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

I had to Add StreamBuilder<dynamic> to the Stream Builder:我必须将StreamBuilder<dynamic>添加到 Stream Builder:

body: StreamBuilder<dynamic>(
        stream: streamQuery,
        builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM