Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Document how to use wakelock in main (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
creativecreatorormaybenot authored Jan 26, 2022
1 parent 2caeaaf commit 7612965
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions wakelock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.1+1

* Documented necessity of ensuring that the `WidgetsBinding` is initialized.

## 0.6.1

* Fixed infinite loop on iOS.
Expand Down
18 changes: 18 additions & 0 deletions wakelock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ bool wakelockEnabled = await Wakelock.enabled;
If you want to wait for the wakelock toggle to complete (which takes an insignificant amount of
time), you can also `await` any of `Wakelock.enable`, `Wakelock.disable`, and `Wakelock.toggle`.

### Ensure the `WidgetsBinding` is initialized

If you want to call `Wakelock.enable()` or the other functions before `runApp()` (e.g. in `main()`),
you will have to ensure that the `WidgetsBinding` is initialized first:

```dart
void main() {
WidgetsFlutterBinding.ensureInitialized();
Wakelock.enable();
runApp(..);
}
```

In general, it is advisable to make your wakelock dependent on certain components within your app
instead, e.g. by only enabling it (continually) when a certain widget is visible.
There is no negative impact in calling `Wakelock.enable()` more often.

## Learn more

If you want to learn more about how this plugin works, how to contribute, etc., you can read through
Expand Down
2 changes: 1 addition & 1 deletion wakelock/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: wakelock
description: >-2
Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on
Android, iOS, macOS, Windows, and web.
version: 0.6.1
version: 0.6.1+1
repository: https://github.com/creativecreatorormaybenot/wakelock/tree/main/wakelock

environment:
Expand Down

0 comments on commit 7612965

Please sign in to comment.