dartpub.dev DartNative · beta
plugins / screen_kit
sc

screen_kit

v0.1.0 MIT

Keep the screen awake and control brightness on iOS and Android over FFI.

Keep the screen awake and read or set screen brightness in DartNative apps on iOS and Android, over FFI with no permissions.

by saitojo1106/screen_kit · DartNative ≥ 3.0 · updated 5 days ago
Install
Free
pubspec.yaml
dependencies:
  screen_kit:
    hosted: https://dartpub.dev
    version: ^0.1.0
Weekly installs
0
Active apps
0
Rating
0.0 · 0
Open issues
0

screen_kit

Keep the screen awake and read or override the screen brightness in DartNative apps on iOS and Android.

  • Wakelock: UIApplication.isIdleTimerDisabled on iOS, FLAG_KEEP_SCREEN_ON on Android. Nothing persists after the app exits.
  • Brightness: UIScreen.brightness on iOS, the activity window's screenBrightness on 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

  1. lib/src/screen.dart – public API and exceptions
  2. lib/src/screen_ffi_bindings.dart – Dart side of the five FFI calls
  3. ios/Classes/DNScreen.swift – iOS implementation
  4. android/src/main/kotlin/io/github/saitojo1106/screen_kit/ – Android implementation; ScreenKitPlugin tracks the foreground activity through Application.ActivityLifecycleCallbacks, DNScreenBridge does the work
  5. android/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.