pageTextMatchPaintCallback method

void pageTextMatchPaintCallback(
  1. Canvas canvas,
  2. Rect pageRect,
  3. PdfPage page
)

Paint callback to highlight the matches.

Use this with PdfViewerParams.pagePaintCallback to highlight the matches.

Implementation

void pageTextMatchPaintCallback(
    ui.Canvas canvas, Rect pageRect, PdfPage page) {
  final range = getMatchesRangeForPage(page.pageNumber);
  if (range == null) return;

  final matchTextColor =
      controller?.params.matchTextColor ?? Colors.yellow.withOpacity(0.5);
  final activeMatchTextColor = controller?.params.activeMatchTextColor ??
      Colors.orange.withOpacity(0.5);

  for (int i = range.start; i < range.end; i++) {
    final m = _matches[i];
    final rect = m.bounds
        .toRect(page: page, scaledPageSize: pageRect.size)
        .translate(pageRect.left, pageRect.top);
    canvas.drawRect(
      rect,
      Paint()
        ..color = m == _currentMatch ? activeMatchTextColor : matchTextColor,
    );
  }
}