我是来自firestore的chargin data,我有这个,我是firestore的新手,我不知道太多,所以你能帮我吗?
Container(
height: 700,
child: GridView.builder(
itemCount: snapShot.data.docs.length,
// ignore: non_constant_identifier_names
itemBuilder: (context, index) => SingleProduct(
name: snapShot.docs.data[index]["name"],
price: snapShot.docs.data[index]["precio"],
image: snapShot.docs.data[index]["image"]),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.7,
crossAxisSpacing: 10,
mainAxisSpacing: 10),
),
)错误是这样的:类'AsyncSnapshot‘没有实例getter 'docs’。接收方:“AsyncSnapshot”的实例已尝试调用: docs
发布于 2020-11-18 23:04:07
这里的问题是您将一个快照与另一个快照弄错了。
您的snapShot变量中有一个AsyncSnapshot实例。此快照可能处于正在加载状态,或者包含您正在查找的的快照的。
你可以检查它是否已经有这样的数据:
final querySnapshot = snapshot.data;
if (querySnapshot == null) return Container();
// Now, you are safe to use your querySnapshot.
querySnapshot.docs
// ...代码中的错误是以下几行:
itemBuilder: (context, index) => SingleProduct(
name: snapShot.docs.data[index]["name"],
price: snapShot.docs.data[index]["precio"],
image: snapShot.docs.data[index]["image"]),在这里,您正在尝试访问snapShot.docs,而不是正确的snapShot.data.docs。
https://stackoverflow.com/questions/64895619
复制相似问题