tryFromMap static method

HackleUrlContext? tryFromMap(
  1. Map<Object?, Object?> map
)

Converts a map sent by the native SDK.

Returns null if url is not a String or channel is not "PUSH" or "IN_APP_MESSAGE".

Implementation

static HackleUrlContext? tryFromMap(Map<Object?, Object?> map) {
  final url = map['url'];
  if (url is! String) {
    return null;
  }

  final HackleUrlChannel channel;
  switch (map['channel']) {
    case 'PUSH':
      channel = HackleUrlChannel.push;
      break;
    case 'IN_APP_MESSAGE':
      channel = HackleUrlChannel.inAppMessage;
      break;
    default:
      return null;
  }

  return HackleUrlContext(url: url, channel: channel);
}