smj6
smj6

Reputation: 21

Flutter wakelock package not allowing the app to go into sleep mode

I am building an application with the latest version of Flutter. I have been testing with a real iOS device and whenever I am in the app my physical device does not go into sleep mode from inactivity. I have the settings on the physical device set to sleep within 30 seconds. I have tried using this package from pub.dev (https://pub.dev/packages/wakelock), but my app still stays on no matter what. The code is relatively simple such as:

await Wakelock.disable();
print(await Wakelock.enabled);
// returns false (device should allow sleep mode)

I would have thought that I didn't even need a package and that the default would allow the device to enter sleep mode. Has anyone encountered this and have a fix?

Upvotes: 1

Views: 3829

Answers (2)

alanjhill
alanjhill

Reputation: 11

I am seeing similar behaviour when running my Flutter app in debug mode on a physical iPhone.

However, if I run in release mode (--release), the device goes to sleep when it should do.

I am using WakelockPlus to enable/disable sleep and this is working as it should too.

Upvotes: 1

creativecreatorormaybenot
creativecreatorormaybenot

Reputation: 126904

I am the author of the wakelock package.

As this kind of problem should generally be a GitHub issue instead of a StackOverflow question, I will write an answer for this instead of a short comment :)


Should the device go to sleep normally?

Yes, it should. And it does normally go to sleep.

I see two options here:

  • either you have something setup incorrectly on your device or have some other service running.
  • you are calling Wakelock.enable at some point after you have disabled it, which causes your device to not go to sleep.

How to solve the issue

I cannot tell you exactly what is happening because it should not from your description.

What you can do is the following: test an app that does not use wakelock at all and see if it goes to sleep. If yes, you can then try to see where you are calling Wakelock.enable and debug that to make sure that it is not being called at all.


After that, if you have more information, please open an issue on GitHub. Please make sure that you can get your device to go to sleep when having another app open before that.

Upvotes: 4

Related Questions