'The following _TypeError was thrown while handling a gesture: type 'Null' is not a subtype of type 'String' flutter
I get this error whenever I press the send message button:
My code below:
void sendMessage(String text) {
var messageJson = {
"message": text,
"isMe": socket.id,
};
socket.emit('message', messageJson);
chatController.chatMessages.add(Message.fromJson(messageJson));
}
void setUpSocketListener() {
socket.on('message-receive', (data) {
print(data);
chatController.chatMessages.add(Message.fromJson(data));
});
}
}
This is the model I made:
class Message {
String message;
String isMe;
Message({required this.message, required this.isMe});
factory Message.fromJson(Map<String, dynamic> json) {
return Message(message: json["message"], isMe: json["isMe"]);
}
}
I don't know what the problem is.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|



