当前位置: 首页 > 知识库问答 >
问题:

类型_InternalLinkedHashMap不是类型的子类型String显示此错误

焦博实
2023-03-14

我正在尝试开发一个消息传递应用程序,它总是抛出一个异常

类型_InternalLinkedHashMap

当我试图给信息的背景颜色。它还表明

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,
            ),
          ),
        );;
      }
    }
    

共有1个答案

古明煦
2023-03-14

这是因为根据您的型号,MessageBubble需要两个strin[sendertext]。但当你经过时:

 final messageText = message.data();

message.data()这里是一个Map

 final messageText = message.get('textField');

 类似资料: