MockVisionBackend class

A scriptable VisionBackend for tests: you emit tracking data by hand instead of running a camera and ML models.

final backend = MockVisionBackend();
await tester.pumpWidget(VirtualTryOn(backend: backend, ...));
backend.emit(someTrackingData);   // -> onFaceDetected / onFaceUpdated
backend.emit(null);               // -> onFaceLost

The mock records lifecycle interactions (started, lastLens, lastPerformanceMode, ...) so tests can assert how the widget drove its backend.

Inheritance

Constructors

MockVisionBackend({bool supported = true, TrackingData? stillResult, CameraController? cameraController})
Creates a mock backend.

Properties

cameraController → CameraController?
The live camera controller opened by start, once initialized. Null before start, after stop/dispose, or on backends with no camera preview (e.g. a not-yet-started or platform-unsupported engine). The renderer (M3) reads this to show a live preview; it's not part of the public API.
no setter
disposed bool
Whether the engine has been disposed.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isSupported bool
False when this backend cannot do live tracking here (wrong platform, missing plugin). The widget then reports backendUnavailable.
no setter
lastLens CameraLens?
The lens the widget last started with.
getter/setter pair
lastPerformanceMode PerformanceMode?
The performance mode the widget last started with.
getter/setter pair
readyCalled bool
Whether ensureReady() has been called.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
started bool
Whether the engine is currently started.
getter/setter pair
stillResult TrackingData?
What detectStill returns. Mutable so a test can change it between calls.
getter/setter pair
tracking Stream<TrackingData?>
A measurement per processed frame, or null when a frame contained no face. Broadcast; listenable across restarts.
no setter

Methods

detectStill(Uint8List bytes) Future<TrackingData?>
Detects the most prominent face in a still image (photo mode). Null when unsupported or no face found.
dispose() Future<void>
Releases everything. The engine is unusable afterwards.
emit(TrackingData? data) → void
Emits one tracking event, exactly as a real backend would per frame: a measurement, or null for "frame processed, no face".
emitError(Object error) → void
Emits a stream error, exercising the widget's backendFailure path.
ensureReady() Future<void>
Loads models/plugins. Safe to call repeatedly; cheap once ready.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start({required CameraLens lens, required PerformanceMode performanceMode}) Future<void>
Begins producing tracking events, opening the camera in the process (see cameraController).
stop() Future<void>
Stops producing events and releases the camera.
toString() String
A string representation of this object.
inherited

Operators

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