current property

  1. @override
Future<double> get current
override

Returns current screen brightness which is current screen brightness value.

The value should be within 0.0 - 1.0. Otherwise, RangeError.range will be throw.

This parameter is useful for user to get screen brightness value after calling setScreenBrightness

Calling this method after calling resetScreenBrightness may return wrong value in iOS because UIScreen.main.brightness returns old brightness value

When _channel.invokeMethod fails to get current brightness, it throws PlatformException with code and message:

Code: -9, Message: value returns null

(Android only) Code: -10, Message: Unexpected error on activity binding Unexpected error when getting activity, activity may be null

(Android only) Code: -11, Message: Could not found system setting screen brightness value Unexpected error when getting brightness from Setting using Settings.System.SCREEN_BRIGHTNESS

Implementation

@override
Future<double> get current async {
  final currentBrightness = await pluginMethodChannel
      .invokeMethod<double>(methodNameGetScreenBrightness);
  if (currentBrightness == null) {
    throw PlatformException(code: "-9", message: "value returns null");
  }

  if (!currentBrightness.isInRange(minBrightness, maxBrightness)) {
    throw RangeError.range(currentBrightness, minBrightness, maxBrightness);
  }

  return currentBrightness;
}