aafanasev / wakelock

This Flutter plugin allows you to keep Android and iOS devices awake, i.e. prevent the screen from sleeping by toggling the wakelock of the device on or off.

Home Page:https://pub.dev/packages/wakelock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wakelock

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.
Wakelock.enable();

// The next line disables the wakelock again.
Wakelock.disable();

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.

About

This Flutter plugin allows you to keep Android and iOS devices awake, i.e. prevent the screen from sleeping by toggling the wakelock of the device on or off.

https://pub.dev/packages/wakelock

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Dart 61.4%Language:Kotlin 25.7%Language:Objective-C 7.4%Language:Ruby 5.6%