Skip to content

Keep the screen always on #106

Description

@DartViet

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 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:

   @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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions