qr_screen_brightness

A small Flutter plugin for temporarily increasing screen brightness while displaying a QR code or other high-contrast content.

The plugin supports Android and iOS. Android changes only the current activity window brightness, while iOS changes the main screen brightness.

Requirements

  • Flutter 3.44 or later
  • Dart 3.12 or later

The iOS implementation supports both Swift Package Manager and CocoaPods.

Installation

flutter pub add qr_screen_brightness

Usage

import 'package:qr_screen_brightness/qr_screen_brightness.dart';

Future<void> withMaximumBrightness(
  Future<void> Function() showQrCode,
) async {
  if (!QrScreenBrightness.isSupported) {
    await showQrCode();
    return;
  }

  await QrScreenBrightness.setMaxBrightness();
  try {
    await showQrCode();
  } finally {
    await QrScreenBrightness.resetBrightness();
  }
}

Always call resetBrightness when the screen that requested the brightness change is closed. Using try/finally ensures that the reset also happens when displaying the content fails.

API behavior

  • isSupported is true on Android and iOS and false elsewhere.
  • getBrightness returns a value from 0.0 to 1.0. On Android it returns null when the activity uses the system-default brightness.
  • setBrightness accepts values from 0.0 to 1.0, inclusive. Invalid values throw an ArgumentError.
  • setMaxBrightness is equivalent to setBrightness(1.0).
  • resetBrightness releases or restores the brightness change made by the plugin.

Brightness operations throw an UnsupportedError on unsupported platforms. Check isSupported before calling them.

Platform behavior

Android changes only the current activity window brightness. It does not write global system brightness and does not require WRITE_SETTINGS. On reset, Android releases the native window brightness override and lets the system brightness rules take over again.

iOS uses UIScreen.main.brightness. When setting brightness, the plugin remembers both the previous and desired values. resetBrightness restores the previous value only if the current brightness still approximately matches the desired value. This is a best-effort approximation of Android's native override release behavior, while avoiding overwriting manual or external brightness changes.

Libraries

qr_screen_brightness
Controls screen brightness on supported mobile platforms.