繁体   English   中英

将我的应用程序升级到空安全后,文档下的红线

[英]After upgrading my app to null safety, red line under docs

在我的完整项目中,在升级到 null 安全后,无论我在哪里使用它,我都会在文档下看到红线。

FutureBuilder(
                  future: db
                      .collection('orders')
                      .where('status', isEqualTo: 'pending')
                  .where('items',arrayContains: this.widget.nameShop)
                      .get(),
                  builder: (context, snapshot) {
                    if (!snapshot.hasData)
                      return Center(
                        child: CircularProgressIndicator(
                          backgroundColor: Colors.blue,
                        ),
                      );
                int count = snapshot.data!.docs.length; //Here on this line
                    return new ListView.builder(
                      scrollDirection: Axis.vertical,
                      itemCount: count,
                      itemBuilder: (context, index) =>
                          inventoryTile(
                              context, snapshot.data!.docs[index], index),
                    );
                  }),

编译器给出的错误是:

error: The getter 'docs' isn't defined for the type 'Object'. 

可能有些东西被弃用了。 请帮忙! 如果需要,我会提供任何进一步的信息。

您需要定义snapshot.data是什么类型的对象,以便您可以调用定义的方法。 您可以通过为 FutureBuilder https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html设置类型参数来做到这一点

例如,如果未来返回一个 DocumentSnapshots:

FutureBuilder<DocumentSnapshot>()

暂无
暂无

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

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