MBPushMessage.fromDictionary constructor

MBPushMessage.fromDictionary(
  1. Map<String, dynamic> dictionary
)

Initializes a push message from the dictionary returned from the APIs. @param dictionary The dictionary returned from the APIs.

Implementation

factory MBPushMessage.fromDictionary(Map<String, dynamic> dictionary) {
  String id = dictionary['id'];
  String title = '';
  String body = '';
  bool sent = false;
  int? badge;
  String? sound;

  String? launchImage;
  Map<String, dynamic>? userInfo;

  if (dictionary['payload'] != null) {
    Map<String, dynamic> payload = dictionary['payload'];

    title = payload['title'] ?? '';
    body = payload['body'] ?? '';
    if (payload['sent'] is int) {
      sent = payload['sent'] == 1;
    } else if (payload['sent'] is bool) {
      sent = payload['sent'];
    }
    badge = payload['badge'];
    sound = payload['sound'];

    launchImage = payload['launch-image'];
    userInfo = payload['custom'];
  }

  return MBPushMessage(
    id: id,
    title: title,
    body: body,
    badge: badge,
    sound: sound,
    launchImage: launchImage,
    userInfo: userInfo,
    sent: sent,
  );
}