fromJson static method

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

Creates a new ChatMember object from a JSON object. This method decides which ChatMember subclass to use based on the status field.

Implementation

static ChatMember fromJson(Map<String, dynamic> json) {
  switch (json['status'] as String) {
    case 'creator':
      return ChatMemberOwner.fromJson(json);
    case 'administrator':
      return ChatMemberAdministrator.fromJson(json);
    case 'member':
      return ChatMemberMember.fromJson(json);
    case 'restricted':
      return ChatMemberRestricted.fromJson(json);
    case 'left':
      return ChatMemberLeft.fromJson(json);
    case 'kicked':
      return ChatMemberBanned.fromJson(json);
    default:
      throw TeleverseException(
        'Unknown ChatMember status: ${json['status']}',
        description: 'The given status does not match any ChatMemberStatus.',
        type: TeleverseExceptionType.invalidParameter,
      );
  }
}