HereNowResult.fromJson constructor

HereNowResult.fromJson(
  1. Map<String, dynamic> object, {
  2. String? channelName,
})

Implementation

factory HereNowResult.fromJson(Map<String, dynamic> object,
    {String? channelName}) {
  var result = DefaultResult.fromJson(object);
  if (result.otherKeys.containsKey('payload')) {
    var payload = result.otherKeys['payload'] as Map<String, dynamic>;

    return HereNowResult._(
        (payload['channels'] as Map<String, dynamic>).map((key, value) =>
            MapEntry(
                key,
                ChannelOccupancy.fromJson(
                    key, value as Map<String, dynamic>))),
        payload['total_occupancy'] as int,
        payload['total_channels'] as int);
  } else {
    return HereNowResult._({
      channelName: ChannelOccupancy.fromJson(channelName!, result.otherKeys)
    }, result.otherKeys['occupancy'] as int, 1);
  }
}