![](/img/trans.png)
[英]How to structure a model in Flutter and Firebase after null safety
[英]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.