简体   繁体   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)

I have the following in my app:我的应用程序中有以下内容:

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();
       }
     }
   }
 }

Pretty standard, but I am getting the error listed above.非常标准,但我收到上面列出的错误。

I have vertified that currentUserID populates with the correct data before this stream is called.在调用此 stream 之前,我已验证 currentUserID 填充了正确的数据。

In testing I have found that this error is perhaps likely caused by the fact that at runtime, "if (snapshot.hasData) {" shows me that there is no data in the snapshot yet.在测试中,我发现这个错误可能是由于在运行时,“if (snapshot.hasData) {”告诉我快照中还没有数据引起的。 If I do anything at all, like minimise the app and refocus it again, all the data loads.如果我做任何事情,比如最小化应用程序并重新聚焦,所有数据都会加载。 So it simply just needs a redraw.所以它只需要重绘。

Is there a way to do an "await" or something on this?有没有办法对此进行“等待”或其他操作? There must be a simple fix for this problem, seems to be a simple issue, but I just can't find a solution in any of the other threads about this.这个问题必须有一个简单的修复,似乎是一个简单的问题,但我在任何其他线程中都找不到关于这个的解决方案。

Anyone have any ideas on how I can either do an await on this stream, or force it to update when it receives data (I kinda thought that was the whole point of a stream, but this examples proves that it doesn't do this).任何人都知道我如何在这个 stream 上等待,或者在它接收到数据时强制它更新(我有点认为这是 stream 的全部意义,但这个例子证明它不会这样做) .

If the error message actually refers to this code, that means currentUserUID is probably an empty string.如果错误消息实际上是指此代码,则意味着currentUserUID可能是一个空字符串。 This is a very common mistake - if you do a Google search for the error message, you will see many others making the same mistake.这是一个非常常见的错误 - 如果您在 Google 上搜索错误消息,您会看到许多其他人也犯了同样的错误。

Print the value of currentUserUID just before you use it in order to verify that it contains the value that you expect.在使用之前打印currentUserUID的值,以验证它是否包含您期望的值。

暂无
暂无

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

相关问题 未捕获的 FirebaseError:无效的文档引用。 文档引用必须有偶数个段,但 todos 有 1 - Uncaught FirebaseError: Invalid document reference. Document references must have an even number of segments, but todos has 1 Firestore addDoc 错误:文档参考无效。 文档引用必须有偶数个段,但 - Firestore addDoc error:Invalid document reference. Document references must have an even number of segments, but “FIRESTORE 内部断言失败:文档引用无效。文档引用必须有偶数个段,但 NewGame 有 1 个” - "FIRESTORE INTERNAL ASSERTION FAILED: Invalid document reference. Document references must have an even number of segments, but NewGame has 1" 文档引用在集合引用上必须有偶数段错误 - Document references must have an even number of segments error on a collection reference 集合引用无效。 集合引用必须有奇数个段 - Invalid collection reference. Collection references must have an odd number of segments Firestore 错误:文档必须具有偶数个路径元素 - Firestore error: A document must have an even number of path elements 集合引用必须有奇数个段 - Collection references must have an odd number of segments Firebase 文档删除奇数段 - Firebase document deletion odd number of segments PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null)) WHEN 在 Flutter 上设置登录 - PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null)) WHEN setting up login on Flutter 文档路径必须是非空字符串,Flutter - Firebase错误? - A document path must be a non-empty string, Flutter - Firebase error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM