type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' 显示此错误
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' shows this error
我正在尝试开发一个消息传递应用程序,但它总是抛出异常
'type '_InternalLinkedHashMap<String,
dynamic>' is not a subtype of type 'String'
当我尝试为消息提供背景颜色时。
它还显示
renderflex overflowed by 99335 pixels
当在列表中使用 MessageBubble 而不是 List 时。
final messages = snapshot.data.docs;
List<**MessageBubble**> messageBubbles = [];
for (var message in messages){
final messageText = message.data();
final messageSender = message.data();
final messageBubble = MessageBubble(sender: messageSender, text:
messageText,);
messageBubbles.add(messageBubble);
}
return Expanded(
child: ListView(
padding: EdgeInsets.symmetric(horizontal: 10,vertical: 20),
children : messageBubbles,
),
);
},
),
Container(
decoration: kMessageContainerDecoration,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: TextField(
onChanged: (value) {
messageText = value;
},
decoration: kMessageTextFieldDecoration,
),
),
FlatButton(
onPressed: () {
_fireStore.collection('messages').add({
'text': messageText,
'sender': loggedInUser.email,
}
);
},
child: Text(
'Send',
style: kSendButtonTextStyle,
),
),
],
),
),
],
),
),
);
}
}
class MessageBubble extends StatelessWidget {
MessageBubble({this.sender, this.text});
String sender;
String text;
@override
Widget build(BuildContext context) {
return Material(
color: Colors.blueAccent,
child: Text(
'$text from $sender',
style: TextStyle(
fontSize: 50,
color: Colors.white,
),
),
);;
}
}
这是因为 MessageBubble
根据您的模型需要两个字符串 [sender
和 text
]。但是当你通过时:
final messageText = message.data();
message.data() 这里是一个Map<String,dynamic>
。此地图中包含文本的字段是什么?
例如,如果在 Firebase 中这个字段被称为 textField
,你需要使用这个:
final messageText = message.get('textField');
我正在尝试开发一个消息传递应用程序,但它总是抛出异常
'type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'
当我尝试为消息提供背景颜色时。 它还显示
renderflex overflowed by 99335 pixels
当在列表中使用 MessageBubble 而不是 List 时。
final messages = snapshot.data.docs;
List<**MessageBubble**> messageBubbles = [];
for (var message in messages){
final messageText = message.data();
final messageSender = message.data();
final messageBubble = MessageBubble(sender: messageSender, text:
messageText,);
messageBubbles.add(messageBubble);
}
return Expanded(
child: ListView(
padding: EdgeInsets.symmetric(horizontal: 10,vertical: 20),
children : messageBubbles,
),
);
},
),
Container(
decoration: kMessageContainerDecoration,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: TextField(
onChanged: (value) {
messageText = value;
},
decoration: kMessageTextFieldDecoration,
),
),
FlatButton(
onPressed: () {
_fireStore.collection('messages').add({
'text': messageText,
'sender': loggedInUser.email,
}
);
},
child: Text(
'Send',
style: kSendButtonTextStyle,
),
),
],
),
),
],
),
),
);
}
}
class MessageBubble extends StatelessWidget {
MessageBubble({this.sender, this.text});
String sender;
String text;
@override
Widget build(BuildContext context) {
return Material(
color: Colors.blueAccent,
child: Text(
'$text from $sender',
style: TextStyle(
fontSize: 50,
color: Colors.white,
),
),
);;
}
}
这是因为 MessageBubble
根据您的模型需要两个字符串 [sender
和 text
]。但是当你通过时:
final messageText = message.data();
message.data() 这里是一个Map<String,dynamic>
。此地图中包含文本的字段是什么?
例如,如果在 Firebase 中这个字段被称为 textField
,你需要使用这个:
final messageText = message.get('textField');