Change Device Brightness using flutter app

662 Views Asked by At

I need to change the brightness of the device using the flutter app. I searched the internet and most of the answers suggested using screen package. After adding it to the project and running the app the logs said that this particular package uses features of flutter that have been deprecated. So, this package won't help me to get my app running seamlessly. Please suggest some other way to get this done like by using the flutter properties itself and not using some 3rd party packages as most of them are not even verified which is not preferable for a product.

1

There are 1 best solutions below

0
Majid On

This seems like the package is using an old version of the depreciated API; you can look at this PR, which appears to upgrade this package and make it more compatible with new APIs.

Alternately, you can use this package screen_brightness, which seems to have better support and use the Federated approach, which will support more platforms.

An example could be: Add the following lines in your pubspec.yaml file

  screen_brightness: ^latest_version

and then

Future<void> setBrightness(double brightness) async {
  try {
    await ScreenBrightness().setScreenBrightness(brightness);
  } catch (e) {
    print(e);
    throw 'Failed to set brightness';
  }
}