繁体   English   中英

Flutter: PlatformException(error, Invalid document reference. Document references must have an even number of segments, but<x> 有 1,空)</x>

[英]Flutter: PlatformException(error, Invalid document reference. Document references must have an even number of segments, but <x> has 1, null)

我的应用程序中有以下内容:

stream: Firestore.instance.collection('stores').document(currentUserUID).snapshots(),
  builder: (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
     if (snapshot.hasData) {
       return ListView.builder(
         //do some stuff here with the data
       } else {
         return LoadingAnimation();
       }
     }
   }
 }

非常标准,但我收到上面列出的错误。

在调用此 stream 之前,我已验证 currentUserID 填充了正确的数据。

在测试中,我发现这个错误可能是由于在运行时,“if (snapshot.hasData) {”告诉我快照中还没有数据引起的。 如果我做任何事情,比如最小化应用程序并重新聚焦,所有数据都会加载。 所以它只需要重绘。

有没有办法对此进行“等待”或其他操作? 这个问题必须有一个简单的修复,似乎是一个简单的问题,但我在任何其他线程中都找不到关于这个的解决方案。

任何人都知道我如何在这个 stream 上等待,或者在它接收到数据时强制它更新(我有点认为这是 stream 的全部意义,但这个例子证明它不会这样做) .

如果错误消息实际上是指此代码,则意味着currentUserUID可能是一个空字符串。 这是一个非常常见的错误 - 如果您在 Google 上搜索错误消息,您会看到许多其他人也犯了同样的错误。

在使用之前打印currentUserUID的值,以验证它是否包含您期望的值。

暂无
暂无

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

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