Committed by
GitHub
Recommend to not call `Wakelock.enable()` inside of `main()` (#171)
* Update pubspec.yaml * Update README.md * Update CHANGELOG.md
Showing
3 changed files
with
22 additions
and
1 deletions
| 1 | +## 0.6.1+2 | ||
| 2 | + | ||
| 3 | +* Documented the recommendation of not calling `Wakelock.enable()` directly inside of `main()`. | ||
| 4 | + | ||
| 1 | ## 0.6.1+1 | 5 | ## 0.6.1+1 |
| 2 | 6 | ||
| 3 | * Documented necessity of ensuring that the `WidgetsBinding` is initialized. | 7 | * Documented necessity of ensuring that the `WidgetsBinding` is initialized. |
| @@ -86,6 +86,23 @@ In general, it is advisable to make your wakelock dependent on certain component | @@ -86,6 +86,23 @@ In general, it is advisable to make your wakelock dependent on certain component | ||
| 86 | instead, e.g. by only enabling it (continually) when a certain widget is visible. | 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. | 87 | There is no negative impact in calling `Wakelock.enable()` more often. |
| 88 | 88 | ||
| 89 | +### Calling `Wakelock.enable()` in `main()` | ||
| 90 | + | ||
| 91 | +As touched on in the previous paragraph, calling `Wakelock.enable()` in your `main()` function is | ||
| 92 | +not the best approach for a number of reasons. | ||
| 93 | + | ||
| 94 | +The most important factors are: | ||
| 95 | + | ||
| 96 | +1. Users expect their screen to automatically turn off unless e.g. a video is playing. | ||
| 97 | + It is unlikely that your whole app requires the screen to always stay on. | ||
| 98 | +2. The wakelock can be released by external sources at any time (e.g. by the OS). | ||
| 99 | + Only calling `Wakelock.enable()` once will most likely mean that the screen turns off at one | ||
| 100 | + point or another anyway. | ||
| 101 | + | ||
| 102 | +This is why you should instead prefer to enable the wakelock whenever components inside of your app | ||
| 103 | +that require the screen to stay on are active. This can e.g. happen in the `build` method of your | ||
| 104 | +widget. | ||
| 105 | + | ||
| 89 | ## Learn more | 106 | ## Learn more |
| 90 | 107 | ||
| 91 | If you want to learn more about how this plugin works, how to contribute, etc., you can read through | 108 | 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+1 | 5 | +version: 0.6.1+2 |
| 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: |
-
Please register or login to post a comment