screen_kit
Keep the screen awake and read or override the screen brightness in DartNative apps on iOS and Android.
- Wakelock:
UIApplication.isIdleTimerDisabledon iOS,FLAG_KEEP_SCREEN_ONon Android. Nothing persists after the app exits. - Brightness:
UIScreen.brightnesson iOS, the activity window'sscreenBrightnesson Android. - One FFI call per operation. No permissions, no polling, no listeners.
Install
screen_kit is published on
dartpub.dev. Add a plain version
dependency to your app's pubspec.yaml; it resolves the same way the
DartNative framework itself does:
dependencies:
screen_kit: ^0.1.0
Then fetch it with:
dn pub get
The generated dartnative_plugin_registrant.dart loads the FFI symbols; call
DartNativePluginRegistrant.registerAll() in main() as usual.
Android requires minSdk 26 or higher; iOS requires iOS 15 or higher.
Usage
import 'package:screen_kit/screen_kit.dart';
// Keep the display on while a recipe, a timer or a video is showing.
await Wakelock.enable();
print(await Wakelock.isEnabled); // true
await Wakelock.disable();
// Brighten the screen for a QR code or a boarding pass, then put it back.
final before = await ScreenBrightness.current; // 0.0 .. 1.0
await ScreenBrightness.set(1.0);
// ... later
await ScreenBrightness.reset();
Public API
| Member | Description |
|---|---|
Wakelock.enable() / disable() / toggle(bool) |
Disable or re-enable the OS idle timer for this app. |
Wakelock.isEnabled |
Future<bool>: whether this app currently keeps the screen on. |
ScreenBrightness.current |
Future<double> from 0.0 to 1.0. |
ScreenBrightness.set(double) |
Override the brightness. Values are clamped to 0.0–1.0. |
ScreenBrightness.reset() |
Undo set. Safe to call when nothing was set. |
ScreenBrightness.isOverridden |
true between set and reset. |
Every call throws ScreenUnavailableException when the platform has no window
to act on yet (on Android, before the first activity is created), and
UnsupportedError on platforms other than iOS and Android.
Platform notes
iOS. UIScreen.brightness is the device brightness: changing it affects
the whole system and stays changed when your app goes to the background or
exits. Call reset() (which restores the value read before the first set)
when the screen that needed it goes away. The wakelock, by contrast, is tied
to the app and is released by the OS when the app is not in the foreground.
Android. Brightness is a per-window override, so it applies only while
your activity is visible and never modifies the system setting. current
returns the override when one is active, otherwise the system brightness
from Settings.System.SCREEN_BRIGHTNESS. The wakelock is FLAG_KEEP_SCREEN_ON
on the activity window, which needs no permission.
How it works
lib/src/screen.dart– public API and exceptionslib/src/screen_ffi_bindings.dart– Dart side of the five FFI callsios/Classes/DNScreen.swift– iOS implementationandroid/src/main/kotlin/io/github/saitojo1106/screen_kit/– Android implementation;ScreenKitPlugintracks the foreground activity throughApplication.ActivityLifecycleCallbacks,DNScreenBridgedoes the workandroid/src/main/cpp/dn_screen.cpp– JNI glue between Dart and Kotlin
Integers and doubles cross the FFI boundary; no strings or callbacks.
Example
example/ is a dn create app that depends on this plugin via path: ../.
cd example
dn pub get
dn run -d <device-id>
The screen shows the current state with buttons to toggle the wakelock and to set the brightness to 20%, 100%, or back to the original value.
Tested on
| Platform | Device | Result |
|---|---|---|
| Android 16 | Pixel 8a | FLAG_KEEP_SCREEN_ON appears on and disappears from the activity window (dumpsys window); the brightness override shows up as mWindowManagerBrightnessOverride=1.0 in dumpsys display and returns to NaN after reset(). |
| iOS 18.7 | iPhone 16e | Setting 100% visibly brightens the display and reset() restores it; the wakelock reports ON after enable(). |
Verified 2026-09-16 with DartNative SDK 3.45.0. dart test and dart analyze
pass for the plugin and the example.
License
MIT. See LICENSE.