我的個人資料頁面中有以下代碼。該代碼在 android 中運行良好,但在 web 上,當我打開我的個人資料頁面時,它會顯示
意外的空值錯誤,
除錯控制臺中指向錯誤的代碼:
return Container(
child: StreamBuilder<DocumentSnapshot>(
stream: FirebaseFirestore.instance
.collection('users')
.doc(profileId)
.snapshots(),
builder: (context,snapshot) {
if (!snapshot.hasData) {
return Container(
alignment: FractionalOffset.center,
child: CircularProgressIndicator());
}
User user = User.fromDocument(snapshot.data!);
return Scaffold(
//all body widgets
);
除錯控制臺顯示
The following TypeErrorImpl was thrown building StreamBuilder<DocumentSnapshot<Object?>>(dirty, state: _StreamBuilderBaseState<DocumentSnapshot<Object?>, AsyncSnapshot<DocumentSnapshot<Object?>>>#556d2):
Unexpected null value.
The relevant error-causing widget was
StreamBuilder<DocumentSnapshot<Object?>>
lib/profile_page.dart:615
uj5u.com熱心網友回復:
我認為您應該將此行User user = User.fromDocument(snapshot.data!);放入else,如下所示:
if (!snapshot.hasData) { // if snapshot has no data this is going to run
return Container(
alignment: FractionalOffset.center,
child: CircularProgressIndicator());
}
else{ // if snapshot has data this is going to run
User user = User.fromDocument(snapshot.data!);
}
uj5u.com熱心網友回復:
檢查網路的 Firebase 權限
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/401560.html
標籤:火力基地 扑 谷歌云firestore 颤动网
上一篇:Firebase:使用FieldPath.documentId()使用多個“orderBy”和“orderBy”進行分頁
