XCameraBackend class abstract
Backend contract that XCameraController dispatches into. The default
implementation calls into native code via the ux/camera /
ux/camera/events channels; tests substitute their own (see
package:ux/testing.dart's FakeXCameraBackend).
Every per-instance call carries a handle returned by create so
the plugin can route to the right native session. Multiple
controllers can hold simultaneous handles.
- Implementers
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
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.
-
availableCameras(
) → Future< List< XCameraDescription> > - Enumerate camera devices. The result is stable for the lifetime of the process.
-
cameraPermissionGranted(
) → Future< bool> - Reads camera authorization without a session, prompt or microphone access.
-
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. -
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.
-
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. -
initialize(
int handle) → Future< void> - Start the session. Native side resolves camera + audio permissions before the future completes. Throws XCameraException("permission_denied") on denial.
-
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.
-
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.
-
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. -
requestCameraPermission(
) → Future< bool> - Requests camera access or opens Settings if another prompt is unavailable. Returns current authorization; Settings changes require a foreground query.
-
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. -
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.
-
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. -
stopVideoRecording(
int handle) → Future< XFile> - Stop recording and return the resulting MP4 on disk.
-
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. -
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.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance ↔ XCameraBackend
-
Swap to inject a fake before any UI code mounts a controller.
getter/setter pair