import 'package:floor/floor.dart'; @entity class Message { @primaryKey int id; int fromId; int toId; String content; String attach; int msgType; int time; int state; int isDelete; Message(id, fromId, toId, content, attach, msgType, time, state, isDelete); factory Message.fromJson(Map json) => Message( json["id"], json["fromId"], json["toId"], json["content"], json["attach"], json["msgType"], json["time"], json["state"], json["isDelete"]); Map toJson() => { "id": id, "fromId": fromId, "toId": toId, "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}) { return Message.fromJson({ "fromId": userId, "toId": toId, "content": content, "attach": attach, "msgType": msgType ?? 0, "time": DateTime.now().millisecondsSinceEpoch, "state": 0, "isDelete": 0 }); }