Firebase 错误状态:DocumentSnapshot平台//颤振中不存在字段
_ref=FirebaseFirestore.instance .collection('conversations/${widget.conversationId}/messages') 我以前尝试过解决这个问题的方法,但没有任何帮助。这就是为什么我想再问一次。如何修复此错误?我的代码如下:Firebase 错误状态:DocumentSnapshot平台//颤振中不存在字段,firebase,flutter,android-studio,google-cloud-firestore,mobile-application,Firebase,Flutter,Android Studio,Google Cloud Firestore,Mobile Application,_ref=FirebaseFirestore.instance .collection('conversations/${widget.conversationId}/messages') 我以前尝试过解决这个问题的方法,但没有任何帮助。这就是为什么我想再问一次。如何修复此错误?我的代码如下: StreamBuilder( stream: _ref.snapshots(), builder: (context, AsyncSnapshot&
StreamBuilder(
stream: _ref.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
return (!snapshot.hasData)
? CircularProgressIndicator()
: ListView(
children: snapshot.data.docs
.map(
(DocumentSnapshot document) => ListTile(
title: Align(
alignment: widget.userId ==
document[
'senderId'] // I have tried document.data()['senderId] but didn't work
? Alignment.centerLeft
: Alignment.centerRight,
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.horizontal(
left: Radius.circular(10),
right: Radius.circular(10)),
color: Theme.of(context).primaryColor,
),
child: Text("Trying Message"),
),
),
),
)
.toList(),
);
},
),
StreamBuilder(
流:_ref.snapshots(),
生成器:(上下文,异步快照){
返回(!snapshot.hasData)
?循环压缩机指示器()
:ListView(
子项:snapshot.data.docs
.地图(
(DocumentSnapshot文档)=>ListTile(
标题:对齐(
对齐:widget.userId==
文件[
'senderId']//我尝试了document.data()['senderId],但没有成功
?左对齐
:Alignment.centerRight,
子:容器(
填充:边缘设置。全部(8),
装饰:盒子装饰(
borderRadius:borderRadius.horizontal(
左:半径。圆形(10),
右:半径。圆形(10)),
颜色:主题。背景。原色,
),
子:文本(“正在尝试的消息”),
),
),
),
)
.toList(),
);
},
),
您的数据库中是否存在此文档的字段?您是对的,我在数据库中定义了“sender”,但我认为字段的名称是“senderId”,所以我称之为“senderId”。它已经解决了。非常感谢。