This Flutter plugin allows you to enable and toggle the screen wakelock on Android and iOS, which prevents the screen from turning off automatically.
Essentially, this allows you to keep the device awake, i.e. prevent the device from sleeping.
To use this plugin, follow the installing guide.
Everything in this plugin is controlled via the
If you want to enable the wakelock, i.e. keep the device awake, you can simply call
and to disable it again, you can use
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.
- Updated documentation.
- Formatting in
- Cleaned up the Android manifest.
- Changed a test name in
- Updated the plugin description.
- Removed unnecessary
Assetsdirectory from the
- Expanded continuous integration to include format checking and code analysis.
- Updated the example's README.
- Improved Travis CI setup.
- Updated badges.
- Updated description.
- Flutter master is used in integration tests now.
- Added integration testing.
- Removed unnecessary Android Manifest permission.
- Added a contributing guide.
- Added CI.
Wakelock.toggle's parameter to a named parameter.
- Improved iOS implementation.
- Made the plugin description more concise.
- Elaborated a bit more in description.
- Renamed functions.
- Improved README.
- Added wakelock permission in Android Manifest.
- Improved README.
- Removed unnecessary files.
- Fixed dependency issue.
- Removed unnecessary dependencies.
- Bumped version to indicate that the plugin is fully usable.
- Improved README's.
- Formatted Dart files.
- The wakelock plugin allows you to toggle the Android and iOS wakelock and retrieve its current status.
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
Integration testing #
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
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies: wakelock: ^0.1.2+8
2. Install it
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.
3. Import it
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 Sep 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.5.0
- pana: 0.12.21
- Flutter: 1.9.1+hotfix.2
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.