toMap method

  1. @override
Map<String, dynamic> toMap()
override

Implementation

@override
Map<String, dynamic> toMap() {
  // Propagate controller and barcodeId to every child annotation before serialization.
  for (final annotation in _annotationsByThreshold.values) {
    if (annotation != null) {
      annotation.controller = controller;
      annotation.barcodeId = barcodeId;
    }
  }

  var json = super.toMap();
  json['annotationsByThreshold'] = {
    for (final entry in _annotationsByThreshold.entries) entry.key.toString(): entry.value?.toMap()
  };

  // Legacy keys, kept for the shared native parsers (and the jsmobile TS layer that reuses
  // them), which still read closeUpAnnotation/farAwayAnnotation/threshold directly.
  var closeUp = _annotationsByThreshold[1.0];
  if (closeUp is BarcodeArInfoAnnotation) {
    json['closeUpAnnotation'] = closeUp.toMap();
  }
  var farAwayEntry = _legacyFarAwayEntry();
  var farAway = farAwayEntry?.value;
  if (farAway is BarcodeArInfoAnnotation) {
    json['farAwayAnnotation'] = farAway.toMap();
  }
  json['threshold'] = farAwayEntry?.key ?? BarcodeArDefaults.view.defaultResponsiveAnnotationThreshold;

  return json;
}