toJson method

Map<String, dynamic> toJson()

Serializes the scan result to a JSON-compatible map.

Implementation

Map<String, dynamic> toJson() {
  return {
    'mode': mode.name,
    'title': mode.title,
    'rawValue': rawValue,
    'fields': fields,
    'isValid': isValid,
    'confidence': confidence,
    'timestamp': timestamp.toIso8601String(),
    'imagePath': imagePath,
    'format': format ?? metadata['format'],
    'documentCategory': documentCategory,
    'isDuplicate': isDuplicate,
    'enhancementsApplied': enhancementsApplied,
    'corners': corners
        ?.map((c) => {'x': c.dx, 'y': c.dy})
        .toList(),
    'boundingBox': boundingBox != null
        ? {
            'left': boundingBox!.left,
            'top': boundingBox!.top,
            'width': boundingBox!.width,
            'height': boundingBox!.height,
          }
        : null,
    'roi': roi != null
        ? {
            'left': roi!.left,
            'top': roi!.top,
            'width': roi!.width,
            'height': roi!.height,
          }
        : null,
    'imageSize': imageSize != null
        ? {'width': imageSize!.width, 'height': imageSize!.height}
        : null,
    'scanDurationMs': scanDuration?.inMilliseconds,
    'metadata': metadata,
    'qualityScore': qualityScore?.toJson(),
    'consensusConfidence': consensusConfidence,
    'verifications': verifications,
    'preprocessingInfo': preprocessingInfo,
    'bankChequeInfo': bankChequeInfo?.toJson(),
    'detectedBarcodes': detectedBarcodes?.map((b) => b.toJson()).toList(),
    'sessionId': sessionId,
    'exportFormat': exportFormat,
    'encryptionStatus': encryptionStatus,
    'watermarkApplied': watermarkApplied,
    'ocrTextResult': ocrTextResult?.toJson(),
  };
}