There is a part of my app, where the user will go to a text screen, and while the user is on that page, I want the device screen not to turn off, but to keep it on, and if the user leaves this page, this function be deactivated. How can I do this with flutter?
CodePudding user response:
Option A: Use a package
I would use a package for what you are trying to accomplish such as:
- Wakelock: https://pub.dev/packages/wakelock
Option B: Write platform specific code
If you don't want to use a package, you should investigate how this functionality can be implemented on Android and iOS in native code. Such as:
- Android: How do I prevent an Android device from going to sleep programmatically?
- iOS: How to disable/enable the sleep mode programmatically in iOS?
Then you should refer to the Flutter documentation for writing code towards specific platforms and integrate it into your codebase: https://docs.flutter.dev/development/platform-integration/platform-channels