wakelock_plus icon indicating copy to clipboard operation
wakelock_plus copied to clipboard

Device Screen still turns Off

Open zionnite opened this issue 1 year ago • 11 comments

Hello Creator,

I started using your package today and I'm grateful for the amount of work you put into this, however, I'm not getting the desired result with this package. I'm creating a Streaming App where users stream to thousands of followers but it seems WakelockPlus.enable() is not working because the device screen still turns off instead of the device's screen being on all through till the user exists the page and the dispose function () which has the WakelockPlus.disable() it's in

current package of interest wakelock_plus: ^1.2.5 win32: ^5.5.0

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale
    en-GB)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor
      --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Community Edition (version 2023.3.2)
[✓] VS Code (version 1.89.0)
[✓] Connected device (4 available)
[✓] Network resources

Please, what I'm I doing wrong?

zionnite avatar May 12 '24 00:05 zionnite

@diegotori , please what do you think of this?

zionnite avatar May 12 '24 00:05 zionnite

What platform are you using?

Also, iOS has known issues where it may not keep the screen on (affecting 16.4 and higher). Once I get myself an iOS device, I'm gonna port the code from Insomnia.swift into the iOS platform channel. The emulator may not be ideal for testing the wakelock.

Nevertheless, I do accept and will review PRs related to this. As long as it passes the existing integration tests, then it'll get merged and released.

If you submit a PR to this effect, then you will also have to update wakelock_plus_platform_interface and regenerate the pigeon classes so that they generate Swift instead of Objective-C.

diegotori avatar May 12 '24 00:05 diegotori

I'm testing on Android at the moment

zionnite avatar May 12 '24 00:05 zionnite

Please, what are the possible things i need to do now to prevent the device screen from sleeping?, my app is already in Production, I need to fix it fast as possible

zionnite avatar May 12 '24 11:05 zionnite

Please, what are the possible things i need to do now to prevent the device screen from sleeping?, my app is already in Production, I need to fix it fast as possible

I need to know which device in particular is causing this issue, which version of Android, etc...

Also, try running the project's example app as an initial sanity check. If that app works without issue, then it might be the way your app is being configured, or even the device itself.

diegotori avatar May 12 '24 13:05 diegotori

Furthermore, after doing a quick Google search, it seems that this is a known issue, where WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, which is what this library adds and removes in its Android platform channel, doesn't end up working.

What's even worse is that when these issues pop up, the poster never specified the device and Android version that it failed to keep the screen on.

Long story short, the Android platform channel is doing this by the book: using WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON with the current activity that is running Flutter.

diegotori avatar May 12 '24 13:05 diegotori

@diegotori , it is working now... I guess clearing the caches by flutter pub cache clean and flutter clean did the trick Thanks for your support

zionnite avatar May 13 '24 03:05 zionnite

Do we have any solution with flutter_background?

harshmdr avatar Aug 07 '24 05:08 harshmdr

Hi @zionnite, were you able to fix this issue?

yash-stage avatar Oct 25 '24 06:10 yash-stage

I'm facing the same issue on iOS devices. Some work fine, while others require a reboot to function temporarily before failing again. Reinstalling the app doesn't help, only rebooting resolves it.

Edit: Seems like not even a reboot is enough for some of my users now

LeonHellqvist avatar Dec 05 '24 13:12 LeonHellqvist

I'm running a Flutter web app on an embedded system using a .local domain over HTTP. The wakelock does neither work when accessing the domain from my desktop machine with Firefox, nor when accessing it with my Android 14 phone with Chrome.

/edit For some reason it works though when I run the app locally using flutter run -d chrome

/edit nvm, my bad, Wake Lock only works on HTTPS or on localhost

higaski avatar Apr 24 '25 11:04 higaski