DependencyReference.fromJson constructor

DependencyReference.fromJson(
  1. dynamic json
)

Implementation

factory DependencyReference.fromJson(json) {
  if (json is Map) {
    if (json.length != 1) {
      throw new StateError('expecting only one entry for dependency');
    }
    switch (json.keys.first as String) {
      case 'path':
        return new PathReference.fromJson(json);
      case 'git':
        return new GitReference.fromJson(json);
      case 'hosted':
        return new ExternalHostedReference.fromJson(json);
      case 'sdk':
        return new SdkReference.fromJson(json);
      default:
        throw new StateError('unexpected dependency type ${json.keys.first}');
    }
  } else if (json is String) {
    return new HostedReference.fromJson(json);
  } else if (json == null) {
    return new HostedReference(VersionConstraint.any);
  } else {
    throw new StateError('Unable to parse dependency $json');
  }
}