qr_screen_brightness 0.0.2
qr_screen_brightness: ^0.0.2 copied to clipboard
Flutter plugin for controlling the current iOS screen or Android activity window brightness.
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 #
isSupportedistrueon Android and iOS andfalseelsewhere.getBrightnessreturns a value from0.0to1.0. On Android it returnsnullwhen the activity uses the system-default brightness.setBrightnessaccepts values from0.0to1.0, inclusive. Invalid values throw anArgumentError.setMaxBrightnessis equivalent tosetBrightness(1.0).resetBrightnessreleases 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.