BaseNotificationModel.fromJson constructor

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

Implementation

factory BaseNotificationModel.fromJson(Map<String, dynamic> json) {

  try{
     var buttonList = json['buttons'] as List?;
    List<ButtonModel>? buttons = buttonList?.map((button) => ButtonModel.fromJson(button)).toList();

    return BaseNotificationModel(
      type: PushType.values.firstWhere((e) => e.toString() == 'PushType.${json['type']}'),
      id: json['id'],
      tags: json['tags'],
      thumb: json['thumb'],
      sound: json['sound'],
      title: json['title'],
      message: json['message'],
      link: json['link'],
      linkId: json['linkId'],
      buttons: buttons,
    );
  }
  catch(e) {
    throw FormatException("Invalid Map : ${e.toString()}");
  }

}