Barcode.fromJson constructor

Barcode.fromJson(
  1. Map json
)

Returns an instance of Barcode from a given json.

Implementation

factory Barcode.fromJson(Map<dynamic, dynamic> json) {
  final type = BarcodeType.values[json['type'].toInt()];
  final format = BarcodeFormatValue.fromRawValue(json['format']);
  final displayValue = json['displayValue'];
  final rawValue = json['rawValue'];
  final rawBytes = json['rawBytes'];
  final boundingBox = RectJson.fromJson(json['rect']);
  final cornerPoints = _listToCornerPoints(json['points']);

  BarcodeValue? value;
  switch (type) {
    case BarcodeType.wifi:
      value = BarcodeWifi.fromJson(json);
      break;
    case BarcodeType.url:
      value = BarcodeUrl.fromJson(json);
      break;
    case BarcodeType.email:
      value = BarcodeEmail.fromJson(json);
      break;
    case BarcodeType.phone:
      value = BarcodePhone.fromJson(json);
      break;
    case BarcodeType.sms:
      value = BarcodeSMS.fromJson(json);
      break;
    case BarcodeType.geoCoordinates:
      value = BarcodeGeoPoint.fromJson(json);
      break;
    case BarcodeType.driverLicense:
      value = BarcodeDriverLicense.fromJson(json);
      break;
    case BarcodeType.contactInfo:
      value = BarcodeContactInfo.fromJson(json);
      break;
    case BarcodeType.calendarEvent:
      value = BarcodeCalenderEvent.fromJson(json);
      break;
    default:
      break;
  }

  return Barcode(
    type: type,
    format: format,
    value: value,
    displayValue: displayValue,
    rawValue: rawValue,
    rawBytes: rawBytes,
    boundingBox: boundingBox,
    cornerPoints: cornerPoints,
  );
}