CoverFitTransform class

A precomputed cover-fit mapping from source-image pixel coordinates to viewport coordinates, with optional horizontal mirroring for a front-camera preview.

Overlay painters receive detector coordinates in the source image's pixel space (the post-rotation, post-downscale size reported by detectionSize) and must map them onto the on-screen preview, which is cover-fitted to the widget. Build one transform per paint call and use map for points and scaleLength for radii or stroke widths:

@override
void paint(Canvas canvas, Size size) {
  final t = CoverFitTransform.cover(
    sourceWidth: imageSize.width,
    sourceHeight: imageSize.height,
    viewWidth: size.width,
    viewHeight: size.height,
    mirror: mirrorHorizontally,
  );
  final p = t.map(landmark.x, landmark.y);
  canvas.drawCircle(p, t.scaleLength(3), paint);
}

The scale is uniform (aspect ratio preserved) and the overflowing axis is centered via offsetX / offsetY. This is the same fit coverFitScaleOffset computes, wrapped with point mapping and mirroring.

Constructors

CoverFitTransform({required double scale, required double offsetX, required double offsetY, required double sourceWidth, bool mirror = false})
Creates a transform from a precomputed scale and offsets. Most callers use CoverFitTransform.cover instead.
const
CoverFitTransform.cover({required double sourceWidth, required double sourceHeight, required double viewWidth, required double viewHeight, bool mirror = false})
Builds a cover-fit transform mapping a sourceWidth x sourceHeight image onto a viewWidth x viewHeight viewport, preserving aspect ratio and centering the overflow. Set mirror for a mirrored front-camera preview.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
mirror bool
Whether x is mirrored about sourceWidth before scaling (front camera).
final
offsetX double
Horizontal offset added after scaling, centering the covered axis.
final
offsetY double
Vertical offset added after scaling, centering the covered axis.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scale double
Uniform scale factor from source pixels to viewport pixels.
final
sourceWidth double
Source image width in pixels, used to reflect x when mirror is set.
final

Methods

map(double x, double y) Offset
Maps a source-space point (x, y) to viewport space.
mapOffset(Offset point) Offset
Maps a source-space point to viewport space.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
scaleLength(double length) double
Scales a source-space length (radius, stroke width) to viewport space.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited