我正在尝试开发一个消息传递应用程序,它总是抛出异常
'type '_InternalLinkedHashMap<String, dynamic>' 不是类型 'String' 的子类型
当我试图为消息赋予背景颜色时。它还显示
renderflex 溢出 99335 像素
在列表而不是列表中使用 MessageBubble 时。
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,
),
),
);;
}
}