XCameraController class
Owns one native camera session. Mirrors the surface
package:camera's CameraController exposes today — every method
signature the chat composer touches has a 1:1 here, plus the
orientation snapshot is passed explicitly on capture calls.
Lifecycle: initialize → use → dispose. After dispose every
other method throws XCameraException("disposed").
- Inheritance
-
- Object
- ChangeNotifier
- ValueNotifier<
XCameraValue> - XCameraController
- Available extensions
Constructors
- XCameraController(XCameraDescription description, XResolutionPreset resolutionPreset, {required bool enableAudio})
- Binds a camera and its preset without touching the device; call initialize to open the session.
Properties
- description → XCameraDescription
-
The camera currently bound; changes with setDescription.
no setter
- enableAudio → bool
-
Whether this session was opened asking for audio.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- resolutionPreset → XResolutionPreset
-
Resolution the session is opened at.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- textureId → int?
-
Texture id once the session has been created (during initialize).
Read by XCameraPreview; null before init or after dispose.
no setter
- value ↔ XCameraValue
-
The current value stored in this notifier.
getter/setter pairinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
buildPreview(
) → Widget - Texture-backed widget that renders the live preview at its parent's size. Hero-flightable.
-
dispose(
) → Future< void> -
Discards any resources used by the object.
override
-
initialize(
) → Future< void> - Configure the native session and begin streaming preview frames.
-
lockCaptureOrientation(
DeviceOrientation orientation) → Future< void> -
Pins captures to
orientation, ignoring how the device is held. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
refreshAudioPermission(
) → Future< void> -
Re-poll the OS for mic permission state and update
value.audioPermissionGranted. Call onAppLifecycleState.resumedto pick up grants made via Settings. -
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
setDescription(
XCameraDescription description) → Future< void> - Switch lenses without tearing down the controller. Blocked while a recording is in flight — call stopVideoRecording first.
-
setFlashMode(
XFlashMode mode) → Future< void> - Sets the flash mode applied to the next still capture.
-
startVideoRecording(
{DeviceOrientation? captureOrientation}) → Future< void> -
Start recording.
captureOrientationbecomes the video file's rotation transform (iOS: AVAssetWriterInput.transform; Android: CameraX targetRotation). Defaults to XSensor.orientation — pass explicitly from tests. -
stopVideoRecording(
) → Future< XFile> - Ends the recording and yields the finished file.
-
subscribe(
VoidCallback callback) → VoidCallback -
Available on Listenable, provided by the ListenableExtension extension
Addscallbackas listener and returns a function to remove it. -
takePicture(
{DeviceOrientation? captureOrientation}) → Future< XFile> -
Capture a still.
captureOrientationis the orientation to embed in the resulting JPEG; defaults to XSensor.orientation read at call time. Tests pass an explicit value to keep the assertion deterministic. -
toString(
) → String -
A string representation of this object.
inherited
-
unlockCaptureOrientation(
) → Future< void> - Returns captures to following the device orientation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
audioPermissionGranted(
) → Future< bool> - Whether the user has granted mic permission to the app. Static because the answer is global to the process — useful from UI that needs the status before any controller has been created (e.g. the camera page's "Tap to enable mic" banner).
-
cameraPermissionGranted(
) → Future< bool> - Reads camera authorization without prompting or creating a session.
-
openSystemSettings(
) → Future< void> - Opens camera privacy Settings on macOS and app Settings on mobile. Re-query authorization on foreground return.
-
requestAudioPermission(
) → Future< bool> - Banner-tap entry point that shows the in-app system mic prompt when the OS still will, and deep-links to Settings on permanent denial. Returns the post-call granted state. Prefer this over jumping straight to openSystemSettings — on a fresh install the mic entry isn't even in the Privacy pane until the first request has been made.
-
requestCameraPermission(
) → Future< bool> - Requests camera access, opening Settings when another prompt is unavailable. Returns current authorization; re-query on foreground return from Settings.