SizeWithUnitAndAspect.fromJSON constructor

SizeWithUnitAndAspect.fromJSON(
  1. Map<String, dynamic> json
)

Implementation

factory SizeWithUnitAndAspect.fromJSON(Map<String, dynamic> json) {
  if (json.containsKey('width') && json.containsKey('height')) {
    return SizeWithUnitAndAspect.widthAndHeight(SizeWithUnit.fromJSON(json));
  } else if (json.containsKey('width') && json.containsKey('aspect')) {
    return SizeWithUnitAndAspect.widthAndAspectRatio(
        DoubleWithUnit.fromJSON(json['width']), (json['aspect'] as num).toDouble());
  } else if (json.containsKey('height') && json.containsKey('aspect')) {
    return SizeWithUnitAndAspect.heightAndAspectRatio(
        DoubleWithUnit.fromJSON(json['height']), (json['aspect'] as num).toDouble());
  } else if (json.containsKey('shorterDimension') && json.containsKey('aspect')) {
    return SizeWithUnitAndAspect.shorterDimensionAndAspectRatio(
        (json['shorterDimension']['value'] as num).toDouble(), (json['aspect'] as num).toDouble());
  }
  throw Exception("Unable to create an instance of SizeWithUnitAndAspect from the given json");
}