[英]Unhandled Exception: NoSuchMethodError: The getter 'uid' was called on null
[英]Firebase/Flutter : Unhandled Exception: NoSuchMethodError: The getter 'isNotEmpty' was called on null
所以我正在嘗試使用 Firestore 中的文檔創建集合,從我在 Form 字段中收集的變量中,代碼如下:
onPressed:() async {
await FirebaseFirestore.instance
.collection(_ICO).add({
"Company name": _compname,
}).then((_){
print("success!");
});
這是我得到的錯誤代碼:
F/crash_dump32(18407): crash_dump.cpp:474] 未能附加到線程 181: 權限被拒絕 I/e.firebase_com(17852): 線程 [5,tid=17868,WaitingInMainSignalCatcherLoop,Thread =0xe1a8d210,peer=0x13240228,” Signal Catcher"]:對信號 3 做出反應 I/e.firebase_com(17852):I/e.firebase_com(17852):將堆棧跟蹤寫入墓碑 E/flutter (17852):[錯誤:flutter/lib/ui/ui_dart_state. cc(186)] 未處理的異常:NoSuchMethodError:在 null 上調用了 getter 'isNotEmpty'。 E/flutter (17852):接收器:null E/flutter (17852):嘗試調用:isNotEmpty *
我還應該提到我在嘗試運行此代碼時使用用戶帳戶登錄。
感謝您的每一次幫助。
您可以更改規則,以便數據庫只能由經過身份驗證的用戶讀取/寫入:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
或者
{ "rules": { ".read": true, ".write": true, } }
要始終可用,請記住在生產中更改它
Go 到數據庫,接下來 go 到數據庫的規則,將規則更改為 true。
好的,所以我終於找到了我的問題的答案,這真的是愚蠢的錯誤,或者更確切地說是 2...
第一個:
Widget _buildICO(){ return TextFormField( decoration: InputDecoration(labelText: 'ICO'), validator: (String value){ if (value.isEmpty){ return 'ICO je potrebné'; } }, onSaved: (String value){ ICO = value; }, ); }
正如您可能已經看到的那樣,我在那里有“onSaved”function,當按下按鈕時我不會調用它,因此發送 null 值。
第二:
尚未為此創建具有正確功能的適當變量:
Map<String, dynamic> data(){ return{ 'compname': compname, 'ICO': ICO, }; }
我的按鈕現在看起來像:
onPressed:() async { if(._formKey.currentState;validate()){ return. } _formKey.currentState;save(). firestore.collection(ICO).doc(compname);set(data());
我回到它並嘗試將文檔寫入空集合后發現問題出在哪里,發現我的值返回為 null(因為您無法創建 null 集合,但您可以將 Z37A6259CC0C1DAE299A78BDZ 值保存到文檔中)
希望我的問題對未來的人有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.