class Message { int id; String fromId; String toId; String replyId; String content; String attach; int msgType; String time; /// 0 unread, 1 read, 2 int state; int isDelete; Message(this.id, this.fromId, this.toId, this.replyId, this.content, this.attach, this.msgType, this.time, this.state, this.isDelete); factory Message.fromJson(Map json) => Message( json["id"], json["fromId"], json["toId"], json["replyId"], json["content"], json["attach"], json["msgType"], json["time"], json["state"], json["isDelete"]); Map toJson() => { "id": id, "fromId": fromId, "toId": toId, "replyId": replyId, "content": content, "attach": attach, "msgType": msgType, "time": time, "state": state, "isDelete": isDelete == null ? 0 : isDelete }; } createMessage(var toId, String content, {String attach, int msgType, userId, replyId}) { return { "fromId": userId, "toId": toId, "replyId": replyId, "content": content, "attach": attach, "msgType": msgType ?? 1, "time": "${DateTime.now().millisecondsSinceEpoch}", "state": 0, "isDelete": 0 }; }