How to keep an application from locking the screen in flutter?
Is there a flag to turn it off an on? Does flutter SDK expose this?
Something like keepAwake(true);
Thank you
The plugin allows you to enable and toggle the screen wakelock, which prevents the screen from turning off automatically. Essentially, this allows you to keep the device awake, i.e. prevent the device from sleeping.
A plugin to keep flutter apps running in the background. Currently only works with Android. It achieves this functionality by running an Android foreground service in combination with a partial wake lock and disabling battery optimizations in order to keep the flutter isolate running.
Usage. Import KeepScreenOn. To keep the screen from turning off, call the turnOn method of the KeepScreenOn class. Calling the turnOff method of the KeepScreenOn class will restore the screen to turn off automatically.
We have all of the six major platforms – iOS, Android, web, Windows, macOS, Linux – all supported as stable parts of the Flutter framework."
As support for the screen plugin that @Tree mentioned has been discontinued and there are some issues with it now, you can use wakelock
.
Full disclosure: I am the author of this plugin, however, it is basically a port of the wakelock functionality from the screen
plugin, with the issues fixed:
import 'package:wakelock/wakelock.dart'; // To keep the screen on: Wakelock.enable(); // or Wakelock.toggle(on: true); // To let the screen turn off again: Wakelock.disable(); // or Wakelock.toggle(on: false);
Learn more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With