creativecreatorormaybenot
Committed by GitHub

Document how to use wakelock in `main` (#168)

  1 +## 0.6.1+1
  2 +
  3 +* Documented necessity of ensuring that the `WidgetsBinding` is initialized.
  4 +
1 ## 0.6.1 5 ## 0.6.1
2 6
3 * Fixed infinite loop on iOS. 7 * Fixed infinite loop on iOS.
@@ -68,6 +68,24 @@ bool wakelockEnabled = await Wakelock.enabled; @@ -68,6 +68,24 @@ bool wakelockEnabled = await Wakelock.enabled;
68 If you want to wait for the wakelock toggle to complete (which takes an insignificant amount of 68 If you want to wait for the wakelock toggle to complete (which takes an insignificant amount of
69 time), you can also `await` any of `Wakelock.enable`, `Wakelock.disable`, and `Wakelock.toggle`. 69 time), you can also `await` any of `Wakelock.enable`, `Wakelock.disable`, and `Wakelock.toggle`.
70 70
  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 +
71 ## Learn more 89 ## Learn more
72 90
73 If you want to learn more about how this plugin works, how to contribute, etc., you can read through 91 If you want to learn more about how this plugin works, how to contribute, etc., you can read through
@@ -2,7 +2,7 @@ name: wakelock @@ -2,7 +2,7 @@ name: wakelock
2 description: >-2 2 description: >-2
3 Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on 3 Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on
4 Android, iOS, macOS, Windows, and web. 4 Android, iOS, macOS, Windows, and web.
5 -version: 0.6.1 5 +version: 0.6.1+1
6 repository: https://github.com/creativecreatorormaybenot/wakelock/tree/main/wakelock 6 repository: https://github.com/creativecreatorormaybenot/wakelock/tree/main/wakelock
7 7
8 environment: 8 environment: