This Flutter plugin allows you to enable and toggle the Android and iOS screen wakelock, which prevents the screen from turning off automatically.
Essentially, this allows you to keep the device awake, i.e. prevent the phone or tablet from sleeping.
To use this plugin, follow the installing guide.
import 'package:wakelock/wakelock.dart'; // ... // The following line will enable the Android and iOS wakelock. Wakelock.enable(); // The next line disables the wakelock again. Wakelock.disable();
import 'package:wakelock/wakelock.dart'; // ... // The following lines of code toggle the wakelock based on a bool value. bool on = true; // The following statement enables the wakelock. Wakelock.toggle(on: on); on = false; // The following statement disables the wakelock. Wakelock.toggle(on: on); // If you want to retrieve the current wakelock status, // you will have to be in an async scope // to await the Future returned by isEnabled. bool isEnabled = await Wakelock.isEnabled;
If you want to wait for the wakelock toggle on Android or iOS to complete (which takes an insignificant amount of time), you can also await any of
This plugin is originally based on
Specifically, the wakelock functionality was extracted into this plugin due to lack of maintenance by the author of the
If you want to contribute to this plugin, follow the contributing guide.
Wakelock.toggle's parameter to a named parameter.
This is a basic example demonstrating the functionality of the wakelock plugin, including enabling & disabling the wakelock and also retrieving the current wakelock status using a
For integration testing, this plugin uses
example/test_driver. The project has a setup for continuous integration, which will run the integration tests to confirm that the plugin is working correctly.
The status for the latest commit is .
If you want to run the integration tests yourself, you can run
flutter drive --target=test_driver/app.dart from the
Add this to your package's pubspec.yaml file:
dependencies: wakelock: ^0.1.2+5
You can install packages from the command line:
$ flutter pub get
Alternatively, your editor might support
flutter pub get.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Jul 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.