addPage method

DocumentPage addPage({
  1. required Uint8List imageBytes,
  2. DocumentFilterMode filterMode = DocumentFilterMode.original,
  3. DocumentCorners? corners,
  4. int width = 640,
  5. int height = 480,
})

Adds a new page to the document session.

Implementation

DocumentPage addPage({
  required Uint8List imageBytes,
  DocumentFilterMode filterMode = DocumentFilterMode.original,
  DocumentCorners? corners,
  int width = 640,
  int height = 480,
}) {
  if (isFull) {
    throw StateError('Document session reached maximum capacity of $maxPages pages.');
  }

  final pageId = '${id}_p${_pages.length + 1}_${DateTime.now().millisecondsSinceEpoch}';
  final resolvedCorners = corners ??
      DocumentScannerService.detectDocumentEdges(
        Size(width.toDouble(), height.toDouble()),
      );

  final page = DocumentPage(
    id: pageId,
    originalBytes: imageBytes,
    filterMode: filterMode,
    corners: resolvedCorners,
    width: width,
    height: height,
  );

  page.applyFilter(filterMode);
  _pages.add(page);
  return page;
}