fluttercommunity / fluttercommunity/wakelock_plus
Keep the screen always on
- Dominant language
- Dart
- Stars
- 109
- Forks
- 97
- Avg merge
- 5d 4h
- Merged PRs (30d)
- 2
Description
Our company is making an app with the requirement that whenever it's running in the foreground, the screen should never turn off.
So far, we've been calling WakeLockPlus.enable() in main(), but we saw a note on the [plugin's page](https://pub.dev/packages/wakelock_plus) that says, "The wakelock can be released by external sources at any time (e.g., by the OS). Only calling WakelockPlus.enable() once will most likely mean that the screen turns off at one point or another anyway."
So, in our case, what's the solution for our app to keep the screen from turning off? We currently have two possible solutions:
1 Using Flutter lifecycle in "MyApp" class, so whenever the app is resumed, we enable to WakeLockPlus again, like this:
```dart
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
// Perform actions when the app is resumed
Wakelockplus.enable();
// e.g., refresh data, re-authenticate, etc.
}
}
```
2 Using Timer, periodically call Wakelockplus.enable()
Thank you.
Contributor guide
Assessment
This issue has not been assessed yet.