fromJson static method

MmPushNotification? fromJson(
  1. dynamic value
)

Returns a new MmPushNotification instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static MmPushNotification? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "MmPushNotification[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "MmPushNotification[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return MmPushNotification(
      ackId: mapValueOfType<String>(json, r'ack_id'),
      platform: mapValueOfType<String>(json, r'platform'),
      serverId: mapValueOfType<String>(json, r'server_id'),
      deviceId: mapValueOfType<String>(json, r'device_id'),
      postId: mapValueOfType<String>(json, r'post_id'),
      category: mapValueOfType<String>(json, r'category'),
      sound: mapValueOfType<String>(json, r'sound'),
      message: mapValueOfType<String>(json, r'message'),
      badge: json[r'badge'] == null ? null : num.parse(json[r'badge'].toString()),
      contAva: json[r'cont_ava'] == null ? null : num.parse(json[r'cont_ava'].toString()),
      teamId: mapValueOfType<String>(json, r'team_id'),
      channelId: mapValueOfType<String>(json, r'channel_id'),
      rootId: mapValueOfType<String>(json, r'root_id'),
      channelName: mapValueOfType<String>(json, r'channel_name'),
      type: mapValueOfType<String>(json, r'type'),
      senderId: mapValueOfType<String>(json, r'sender_id'),
      senderName: mapValueOfType<String>(json, r'sender_name'),
      overrideUsername: mapValueOfType<String>(json, r'override_username'),
      overrideIconUrl: mapValueOfType<String>(json, r'override_icon_url'),
      fromWebhook: mapValueOfType<String>(json, r'from_webhook'),
      version: mapValueOfType<String>(json, r'version'),
      isIdLoaded: mapValueOfType<bool>(json, r'is_id_loaded'),
    );
  }
  return null;
}