簡體   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