[英]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.