wakelock 0.1.3+4

  • Readme
  • Changelog
  • Example
  • Installing
  • 98


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.

Usage #

To use this plugin, follow the installing guide.

Implementation #

Everything in this plugin is controlled via the Wakelock class.
If you want to enable the wakelock, i.e. keep the device awake, you can simply call Wakelock.enable and to disable it again, you can use Wakelock.disable:

import 'package:wakelock/wakelock.dart';
// ...

// The following line will enable the Android and iOS wakelock.

// The next line disables the wakelock again.

For more advanced usage, you can pass a bool to Wakelock.toggle to enable or disable the wakelock and also retrieve the current wakelock status using Wakelock.isEnabled:

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 Wakelock.enable, Wakelock.disable, and Wakelock.toggle.

Notes #

This plugin is originally based on screen.
Specifically, the wakelock functionality was extracted into this plugin due to lack of maintenance by the author of the screen plugin.

If you want to contribute to this plugin, follow the contributing guide.

0.1.3+4 #

  • Fix iOS simulator issue.

0.1.3+3 #

  • Fix Flutter SDK version constraint.

0.1.3+2 #

  • Fix pubspec.yaml.

0.1.3+1 #

  • Updated pubspec.yaml to match new format.

0.1.3 #

  • Completed AndroidX migration.

0.1.2+8 #

  • Updated documentation.

0.1.2+7 #

  • Formatting in AndroidManifest.xml.

0.1.2+6 #

  • Cleaned up the Android manifest.
  • Changed a test name in test_driver.
  • Updated the plugin description.
  • Updated README.md.
  • Updated CONTRIBUTING.md.
  • Updated .travis.yml.
  • Removed unnecessary Assets directory from the ios folder.

0.1.2+5 #

  • Expanded continuous integration to include format checking and code analysis.

0.1.2+4 #

  • Updated the example's README.

0.1.2+3 #

  • Improved Travis CI setup.
  • Updated badges.

0.1.2+2 #

  • Updated description.
  • Flutter master is used in integration tests now.

0.1.2+1 #

  • Added integration testing.
  • Removed unnecessary Android Manifest permission.
  • Added a contributing guide.
  • Added CI.

0.1.2 #

  • Changed Wakelock.toggle's parameter to a named parameter.
  • Improved iOS implementation.

0.1.1+2 #

  • Made the plugin description more concise.

0.1.1+1 #

  • Elaborated a bit more in description.

0.1.1 #

  • Renamed functions.
  • Improved README.

0.1.0+3 #

  • Added wakelock permission in Android Manifest.

0.1.0+2 #

  • Improved README.
  • Removed unnecessary files.

0.1.0+1 #

  • Fixed dependency issue.
  • Removed unnecessary dependencies.

0.1.0 #

  • Bumped version to indicate that the plugin is fully usable.
  • Improved README's.
  • Formatted Dart files.

0.0.1 #

  • The wakelock plugin allows you to toggle the Android and iOS wakelock and retrieve its current status.


Example #

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 FutureBuilder.

See example/lib/main.dart.

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 build status.

If you want to run the integration tests yourself, you can run flutter drive --target=test_driver/app.dart from the example directory.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  wakelock: ^0.1.3+4

2. Install it

You can install packages from the command line:

with Flutter:

$ 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:

import 'package:wakelock/wakelock.dart';
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]
Learn more about scoring.

We analyzed this package on Jan 22, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8