![](/img/trans.png)
[英]Flutter - CastError (Null check operator used on a null value)
[英]Flutter Firestore "_CastError (Null check operator used on a null value)" Error
我收到這樣的錯誤:
為什么會這樣? 我該如何解決?
代碼:
FirebaseAuth _auth = FirebaseAuth.instance;
FirebaseFirestore _firestore = FirebaseFirestore.instance;
// ...
_auth.createUserWithEmailAndPassword(
email: _emailController.text,
password: _passwordController.text,
);
_firestore.collection("Users").doc(_auth.currentUser!.uid).set({
"ID": _auth.currentUser?.uid,
"Email": _emailController.text,
"Phone": _phoneController.text,
"Name": _nameController.text,
"Surname": _surnameController.text,
"Photo": "https://firebasestorage.googleapis.com/v0/b/teen-software-stock-tracking.appspot.com/o/default.jpg?alt=media&token=0eec2e1f-2ccf-4bda-8664-3d3f018621b3",
"Level": 0,
"ProductRight": 10,
"AddedProduct": 0,
});
用戶是在 Firebase Auth 中創建的,但我無法將數據寫入 Firestore。
正如 Frank 在評論中提到的那樣作為社區維基回答:
當您在變量上使用時:您是在告訴編譯器,“看。這個左邊的東西永遠不會為空”。 並且錯誤消息指出您破壞了 promise,因為當前用戶是 null。檢查從 createUserWithEmailAndPassword 返回的結果可能會很好,如果創建成功,其中也包括用戶。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.