Son*_*vli 5 android dart firebase flutter google-cloud-firestore
我通过文档 ID 获取数据,但收到此错误:
\n错误状态:无法获取 DocumentSnapshotPlatform 上不存在的字段
\n它正在工作,我可以通过文档 id 从 firebase 获取数据,但它在调试控制台中给出错误。
\n我正在使用StreamBuilder获取数据:
\n StreamBuilder(\n stream: _databaseService.productCollection.doc(docID).snapshots(),\n builder: (context, snapshot) {\n if (!snapshot.hasData) {\n return Center(\n child: CircularProgressIndicator(\n valueColor:\n new AlwaysStoppedAnimation<Color>(Colorsx.mainColor),\n ),\n );\n }\n var document1 = snapshot.data;\n\n return Container(\n decoration: BoxDecoration(\n color: Colorsx.mainColor,\n borderRadius: radius,\n ),\n // color: Colorsx.mainColor,\n child: Column(\n children: [\n Expanded(\n child: Row(\n mainAxisAlignment: MainAxisAlignment.spaceEvenly,\n children: [\n Chip(\n label: LabelText1("\xc3\x9cr\xc3\xbcn Ad\xc4\xb1: "),\n backgroundColor: Colorsx.mainColor,\n ),\n Chip(\n shadowColor: Colorsx.mainColor2,\n elevation: 24,\n label: LabelText1(document1["productName"] ?? ""),\n backgroundColor: Colorsx.mainColor2,\n ),\n ],\n ),\n ),\n ],\n ),\n );\n },\n ),\nRun Code Online (Sandbox Code Playgroud)\n我找不到这里的问题是什么,但根据我的研究,它与地图有关。 \有什么想法吗?
\n当此代码运行时,看起来 _databaseService.productCollection.doc(docID)可能不会在某个时刻指向现有文档。如果您随后document1["productName"]像以前那样调用它,它会引发您看到的错误。
因此,您需要决定当这种情况发生时要渲染什么(即使只是短暂的)。例如,您可以将其CircularProgressIndicator停留在屏幕上,直到文档可用:
if (!snapshot.hasData || !snapshot.data.exists) {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7530 次 |
| 最近记录: |