FakeXCameraBackend class
In-memory backend for XCameraController tests. Swap in via
XCameraBackend.instance = FakeXCameraBackend(...) before any UI
mounts; restore with XCameraBackend.instance = MethodChannelXCameraBackend() in tearDown.
Captures every call into per-method lists for assertions, and lets tests drive events deterministically via emitOrientationChanged and friends.
- Implemented types
Constructors
-
FakeXCameraBackend({List<
XCameraDescription> cameras = const [], Size previewSize = const Size(1920, 1080), String picturePath = '/tmp/fake_picture.jpg', String videoPath = '/tmp/fake_video.mp4'}) - Binds the cameras this backend reports and the canned results its capture calls return.
Properties
- audioPermission ↔ bool
-
Audio permission state returned by audioPermissionGranted.
Tests mutate this to drive the mic-permission UI banner.
getter/setter pair
- audioPermissionCalls ↔ int
-
How many times audioPermissionGranted has been called.
getter/setter pair
- availableCamerasCalls ↔ int
-
How many times availableCameras has been called.
getter/setter pair
- cameraPermission ↔ bool
-
Authorization returned by cameraPermissionGranted.
getter/setter pair
- cameraPermissionCalls ↔ int
-
Number of camera authorization queries.
getter/setter pair
- cameraPermissionError ↔ XCameraException?
-
Failure returned instead of the configured authorization.
getter/setter pair
-
cameras
↔ List<
XCameraDescription> -
Cameras returned by availableCameras. Mutable so tests can swap
the set between assertions.
getter/setter pair
-
createCalls
→ List<
({String cameraId, bool enableAudio, XResolutionPreset preset})> -
Arguments of every create call, in order.
final
- createError ↔ XCameraException?
-
If non-null, create throws this exception instead of returning
a result — exercises permission denial / device busy paths.
getter/setter pair
-
disposeCalls
→ List<
int> -
Handles passed to disposeInstance, in order.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
initializeCalls
→ List<
int> -
Handles passed to initialize, in order.
final
- initializeError ↔ XCameraException?
-
Optional override; set to throw on any particular method to
drive failure paths.
getter/setter pair
-
lockCaptureOrientationCalls
→ List<
({int handle, DeviceOrientation orientation})> -
Arguments of every lockCaptureOrientation call, in order.
final
- openSettingsCalls ↔ int
-
How many times openSettings has been called.
getter/setter pair
- picturePath ↔ String
-
Path every takePicture resolves to.
getter/setter pair
- previewSize ↔ Size
-
Preview size every create reports.
getter/setter pair
- requestAudioPermissionCalls ↔ int
-
How many times requestAudioPermission has been called.
getter/setter pair
- requestAudioPermissionResult ↔ bool
-
Result returned by requestAudioPermission. Tests mutate to
exercise grant / permanent-denial paths.
getter/setter pair
- requestCameraPermissionCalls ↔ int
-
Number of explicit camera authorization requests.
getter/setter pair
- requestCameraPermissionError ↔ XCameraException?
-
Request failure that leaves authorization unchanged.
getter/setter pair
- requestCameraPermissionResult ↔ bool
-
Authorization returned and stored by requestCameraPermission.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
setDescriptionCalls
→ List<
({String cameraId, int handle})> -
Arguments of every setDescription call, in order.
final
-
setFlashModeCalls
→ List<
({int handle, XFlashMode mode})> -
Arguments of every setFlashMode call, in order.
final
-
startVideoRecordingCalls
→ List<
({int handle, DeviceOrientation snapshotOrientation})> -
Arguments of every startVideoRecording call, in order.
final
- startVideoRecordingError ↔ XCameraException?
-
If non-null, startVideoRecording throws this.
getter/setter pair
-
stopVideoRecordingCalls
→ List<
int> -
Handles passed to stopVideoRecording, in order.
final
- stopVideoRecordingError ↔ XCameraException?
-
If non-null, stopVideoRecording throws this.
getter/setter pair
-
takePictureCalls
→ List<
({int handle, DeviceOrientation snapshotOrientation})> -
Arguments of every takePicture call, in order.
final
- takePictureError ↔ XCameraException?
-
If non-null, takePicture throws this instead of returning a file.
getter/setter pair
-
unlockCaptureOrientationCalls
→ List<
int> -
Handles passed to unlockCaptureOrientation, in order.
final
- videoPath ↔ String
-
Path every stopVideoRecording resolves to.
getter/setter pair
Methods
-
audioPermissionGranted(
) → Future< bool> -
True iff the user has granted microphone access. Cheap; safe to
re-poll on app foregrounding to detect grants made via Settings.
override
-
availableCameras(
) → Future< List< XCameraDescription> > -
Enumerate camera devices. The result is stable for the lifetime
of the process.
override
-
cameraPermissionGranted(
) → Future< bool> -
Reads camera authorization without a session, prompt or microphone access.
override
-
create(
{required String cameraId, required bool enableAudio, required XResolutionPreset preset}) → Future< XCameraCreateResult> -
Allocate a native camera instance bound to
cameraId. Returns the handle (for subsequent calls), the FlutterTexture id (for the preview widget), and the sensor-natural-orientation preview size.override -
disposeInstance(
int handle) → Future< void> -
Tear down the session. Cancels any in-flight recording, releases
the camera device and the audio claim. Safe to call repeatedly;
no-op once disposed.
override
-
emitDiagnostic(
int handle, String message) → void -
Pushes a recorder diagnostic for
handle. -
emitOrientationChanged(
int handle, DeviceOrientation orientation) → void -
Push a
deviceOrientationChangedevent forhandle. The subscribed controller will update itsvalue.deviceOrientation. -
emitPreviewSizeChanged(
int handle, Size size) → void -
Push a
previewSizeChangedevent forhandle. Tests that need to simulate Android's async preview-size resolve drive this. -
emitSessionError(
int handle, String code, [String? description]) → void -
Pushes a session error for
handle. -
emitSessionInterrupted(
int handle, String reason) → void -
Pushes a session interruption for
handle. -
emitSessionResumed(
int handle) → void -
Pushes a session resume for
handle. -
events(
int handle) → Stream< XCameraEvent> -
Live event stream for
handle: device-orientation changes, session errors, interrupted/resumed lifecycle pings. The controller subscribes during initialize and unsubscribes on disposeInstance.override -
initialize(
int handle) → Future< void> -
Start the session. Native side resolves camera + audio permissions
before the future completes. Throws
XCameraException("permission_denied") on denial.
override
-
lockCaptureOrientation(
int handle, DeviceOrientation orientation) → Future< void> -
Pin the preview's connection orientation. Used today only to lock
the preview to portrait so it never appears stretched/rotated.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
openSettings(
) → Future< void> -
Opens camera privacy Settings on macOS and app Settings on mobile.
Authorization changes require a foreground query.
override
-
requestAudioPermission(
) → Future< bool> -
Attempt to grant mic access. Shows the in-app system prompt when
the OS is willing to surface one (fresh install, or a first
denial that's still retryable on Android); on permanent denial,
deep-links into Settings and resolves to
false. Returns the post-call granted state. Avoids the fresh-install trap where the mic entry isn't in the Privacy pane untilrequestAccesshas fired at least once.override -
requestCameraPermission(
) → Future< bool> -
Requests camera access or opens Settings if another prompt is unavailable.
Returns current authorization; Settings changes require a foreground query.
override
-
setDescription(
int handle, String cameraId) → Future< ({int previewRotationQuarterTurns, Size previewSize})> -
Swap to a different camera mid-session. Resets the lock and clears
any pending recording. Returns the new preview size and rotation;
the size may again be
Size.zeroinitially on Android, with a follow-up XCameraPreviewSizeChanged event.override -
setFlashMode(
int handle, XFlashMode mode) → Future< void> -
Set the flash mode used for the next takePicture. On front cameras
without a screen-flash fallback the backend silently no-ops; the
caller is responsible for not offering flash UI there.
override
-
startVideoRecording(
int handle, DeviceOrientation snapshotOrientation) → Future< void> -
Begin recording video.
snapshotOrientationis baked into the writer track's transform — the file plays back rotated even if the device returns to portrait mid-recording.override -
stopVideoRecording(
int handle) → Future< XFile> -
Stop recording and return the resulting MP4 on disk.
override
-
takePicture(
int handle, DeviceOrientation snapshotOrientation) → Future< XFile> -
Take a still photo.
snapshotOrientationis applied to the photo connection just before capture so the file's EXIF orientation matches how the user was holding the device.override -
toString(
) → String -
A string representation of this object.
inherited
-
unlockCaptureOrientation(
int handle) → Future< void> -
Release the orientation lock — the preview falls back to following
physical device orientation. Unused by the chat composer; kept for
API symmetry.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited