我最近一直在使用 Flutter 和 Firebase,我今天遇到了一個令人困惑的問題,希望得到一些幫助。
我在 Firebase Cloud Firestore 中有一個集合,其中包含名稱很長的檔案。下面的照片顯示了它們:

我在 Dart 中撰寫了一個函式來檢查特定檔案的存在,它也很簡單:
Future<String> checkForExistance(String mnemonic) async {
final String seedHex = bip39.mnemonicToSeedHex(mnemonic);
final snapShot = await FirebaseFirestore.instance
.collection('wallets')
.doc(seedHex)
.get();
if (!snapShot.exists) {
if (kDebugMode) {
print('SnapShot not exist');
}
return 'NO_IDEA';
} else {
if (kDebugMode) {
print('Snapshot Exist');
}
return seedHex;
}
}
回傳結果始終是“快照不存在”。
即使我確定我正在檢查是否存在我需要的東西,回傳總是'SnapShot 不存在'。
即使我硬編碼了其中一個檔案的名稱,結果也是“快照不存在”(這讓我感到困惑)。
Future<String> checkForExistance(String mnemonic) async {
final String seedHex = bip39.mnemonicToSeedHex(mnemonic);
final snapShot = await FirebaseFirestore.instance
.collection('wallets')
.doc(**'hard coded'**)
.get();
if (!snapShot.exists) {
if (kDebugMode) {
print('SnapShot not exist');
}
return 'NO_IDEA';
} else {
if (kDebugMode) {
print('Snapshot Exist');
}
return seedHex;
}
}
因此,我嘗試創建一個名稱較短的檔案(影像末尾的“s”)并對其進行硬編碼,結果按預期回傳,即“快照存在”。
是因為我的檔案名稱太長導致 Firebase 搜索無法按預期作業嗎?
感謝大家的幫助。
uj5u.com熱心網友回復:
從螢屏截圖中我可以看到,檔案名稱以斜體顯示,這意味著沒有具有該名稱的檔案,控制臺僅顯示它,因為該路徑下有子集合。
這也解釋了為什么您不能通過 API 加載這些檔案,沒有要加載的檔案。
您必須已經知道這些路徑的存在,或者您可以使用集合組查詢從子集合中加載檔案,然后從中確定父路徑。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/465071.html
上一篇:顫振if陳述句不起作用
