Dala.Wakelock (dala v0.0.13)

Copy Markdown View Source

Screen wakelock — keep the device screen on.

Mirrors the wakelock_plus Flutter plugin API. No special permissions required on either platform.

Usage

# Keep the screen on
Dala.Wakelock.enable()

# Let the screen turn off again
Dala.Wakelock.disable()

# Toggle based on a boolean
Dala.Wakelock.toggle(enable: true)

# Check current state
if Dala.Wakelock.enabled?(), do: ...

Platform details

  • iOS — sets UIApplication.sharedApplication.idleTimerDisabled.
  • Android — sets WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON on the main Activity's window.

No permissions are needed because this is a screen wakelock, not a partial (CPU) wakelock that would keep the app alive in the background.

Summary

Functions

Disable the screen wakelock. The screen will be allowed to turn off normally.

Enable the screen wakelock. The device screen will stay on until disable/0 is called.

Returns true if the screen wakelock is currently enabled.

Toggle the wakelock on or off.

Functions

disable()

@spec disable() :: :ok

Disable the screen wakelock. The screen will be allowed to turn off normally.

enable()

@spec enable() :: :ok

Enable the screen wakelock. The device screen will stay on until disable/0 is called.

enabled?()

@spec enabled?() :: boolean()

Returns true if the screen wakelock is currently enabled.

toggle(list)

@spec toggle(keyword()) :: :ok

Toggle the wakelock on or off.

Dala.Wakelock.toggle(enable: true)   # enable
Dala.Wakelock.toggle(enable: false)  # disable