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

Commit 7612965

Browse files
Document how to use wakelock in main (#168)
1 parent 2caeaaf commit 7612965

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

wakelock/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.1+1
2+
3+
* Documented necessity of ensuring that the `WidgetsBinding` is initialized.
4+
15
## 0.6.1
26

37
* Fixed infinite loop on iOS.

wakelock/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ bool wakelockEnabled = await Wakelock.enabled;
6868
If you want to wait for the wakelock toggle to complete (which takes an insignificant amount of
6969
time), you can also `await` any of `Wakelock.enable`, `Wakelock.disable`, and `Wakelock.toggle`.
7070

71+
### Ensure the `WidgetsBinding` is initialized
72+
73+
If you want to call `Wakelock.enable()` or the other functions before `runApp()` (e.g. in `main()`),
74+
you will have to ensure that the `WidgetsBinding` is initialized first:
75+
76+
```dart
77+
void main() {
78+
WidgetsFlutterBinding.ensureInitialized();
79+
Wakelock.enable();
80+
81+
runApp(..);
82+
}
83+
```
84+
85+
In general, it is advisable to make your wakelock dependent on certain components within your app
86+
instead, e.g. by only enabling it (continually) when a certain widget is visible.
87+
There is no negative impact in calling `Wakelock.enable()` more often.
88+
7189
## Learn more
7290

7391
If you want to learn more about how this plugin works, how to contribute, etc., you can read through

wakelock/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: wakelock
22
description: >-2
33
Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on
44
Android, iOS, macOS, Windows, and web.
5-
version: 0.6.1
5+
version: 0.6.1+1
66
repository: https://github.com/creativecreatorormaybenot/wakelock/tree/main/wakelock
77

88
environment:

0 commit comments

Comments
 (0)