Message.fromJson constructor

Message.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory Message.fromJson(Map<String, dynamic> json) => Message(
      id: json['id']?.toString() ?? '',
      message: json['message']?.toString() ?? '',
      createdAt:
          DateTime.tryParse(json['createdAt'].toString()) ?? DateTime.now(),
      sentBy: json['sentBy']?.toString() ?? '',
      replyMessage: json['reply_message'] is Map<String, dynamic>
          ? ReplyMessage.fromJson(json['reply_message'])
          : const ReplyMessage(),
      reaction: json['reaction'] is Map<String, dynamic>
          ? Reaction.fromJson(json['reaction'])
          : null,
      messageType: MessageType.tryParse(json['message_type']?.toString()) ??
          MessageType.text,
      voiceMessageDuration: Duration(
        microseconds:
            int.tryParse(json['voice_message_duration'].toString()) ?? 0,
      ),
      status: MessageStatus.tryParse(json['status']?.toString()) ??
          MessageStatus.pending,
    );