TorchController class
A controller for managing torch (flashlight) operations. Provides instance-based methods for cleaner architecture.
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
-
torchStream
→ Stream<
bool> -
Returns a stream of torch state changes.
Emits
truewhen torch is enabled,falsewhen disabled. Useful when another app changes the flashlight state.no setter
Methods
-
disable(
) → Future< void> - Disables the torch (flashlight) on the device.
-
dispose(
) → void - Disposes the controller and cancels all timers.
-
enable(
{Duration? duration, FlashMode mode = FlashMode.torch}) → Future< void> -
Enables the torch (flashlight) on the device.
Optionally specify a
durationto automatically turn off the torch after the specified time.mode- The flash mode to use (torch or flash). -
fadeIn(
{Duration duration = const Duration(milliseconds: 500)}) → Future< void> - Fades in the torch smoothly over the specified duration. Uses torch strength control for smooth transition on supported devices. Falls back to immediate enable on devices without strength control.
-
fadeOut(
{Duration duration = const Duration(milliseconds: 500)}) → Future< void> - Fades out the torch smoothly over the specified duration. Uses torch strength control for smooth transition on supported devices. Falls back to immediate disable on devices without strength control.
-
getCapabilities(
) → Future< TorchCapabilities> - Returns the capabilities of the torch on the current platform.
-
getCurrentStrength(
) → Future< int> - Returns the current torch strength level. Returns 0 if not supported or torch is off.
-
getMaxStrength(
) → Future< int> - Returns the maximum torch strength level supported by the device. Returns 0 if not supported by the device.
-
isAvailable(
) → Future< bool> - Checks if the torch (flashlight) functionality is available on the device.
-
isOn(
) → Future< bool> - Returns the current torch state (true if on, false if off).
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setStrength(
int strength) → Future< void> -
Sets the torch strength level.
strengthshould be between 0 and getMaxStrength(). Throws an error if not supported by the device. -
startCustomBlink(
BlinkPattern pattern) → Future< void> - Starts a custom blink pattern. The pattern is a list of durations in milliseconds. The torch alternates between on and off states for each duration. The pattern repeats indefinitely until stopped.
-
startForegroundService(
) → Future< void> - Starts foreground service for background torch operation (Android only). Required for torch to continue working when app is in background.
-
startNativeBlink(
int interval) → Future< void> -
Starts native periodic blinking for better performance.
Uses native timers instead of Dart timers for more consistent timing and lower overhead.
interval- The interval between on/off toggles in milliseconds. -
startSOS(
) → Future< void> - Starts SOS mode using Morse code pattern (... --- ...). Uses standard Morse code timing:
-
stopCustomBlink(
) → Future< void> - Stops the custom blink pattern by canceling the timer and disabling the torch.
-
stopForegroundService(
) → Future< void> - Stops foreground service (Android only).
-
stopNativeBlink(
) → Future< void> - Stops native periodic blinking.
-
stopPeriodically(
) → Future< void> - Stops the torch flashlight from flashing periodically by canceling any existing timer.
-
stopSOS(
) → Future< void> - Stops SOS mode by canceling the SOS timer and disabling the torch.
-
toggle(
) → Future< void> - Toggles the torch (flashlight) on/off.
-
togglePeriodically(
{required Duration onOffInterval, Duration stopAfterDuration = const Duration(hours: 1), bool disableTorchRandomlyInSeconds = false, bool disableTorchRandomlyInMinutes = false, bool disableTorchRandomlyInHours = false}) → Future< void> -
Toggles the torch (flashlight) periodically at specified intervals.
onOffInterval- The interval between on/off toggles.stopAfterDuration- The duration after which to stop toggling (default: 1 hour).disableTorchRandomlyInSeconds- If true, randomly stops after a number of seconds.disableTorchRandomlyInMinutes- If true, randomly stops after a number of minutes.disableTorchRandomlyInHours- If true, randomly stops after a number of hours. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited