Giter VIP home page Giter VIP logo

flutter_keep_screen_on's Introduction

KeepScreenOn

This plugin disables automatic screen off and prevents the screen from turning off.

Getting Started

Add this to your package's pubspec.yaml file:

dependencies:
  keep_screen_on: ^2.1.0

Usage

Import KeepScreenOn.

import 'package:keep_screen_on/keep_screen_on.dart';

To keep the screen from turning off, call the turnOn method of the KeepScreenOn class.

// Keep the screen on.
KeepScreenOn.turnOn();

Calling the turnOff method of the KeepScreenOn class will restore the screen to turn off automatically.
Alternatively, you can do the same by specifying false as the argument to the turnOn method.

// Reset
KeepScreenOn.turnOff();

// or...
KeepScreenOn.turnOn(false);

You can check if the screen is not turned off by checking the isOn property or isOff property.
Since isOn and isOff return Future , you need to use "await" or receive the value with the "then" method.

Future<bool> getScreenKeepOn() async {
  return await KeepScreenOn.isOn; 
}

Future<bool> getScreenKeepOff() async {
  return await KeepScreenOn.isOff;
}

Attention

When you call the turnOn method with no arguments or with true,
Android sets android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON for the activity window as an internal action.
iOS sets UIApplication.shared.isIdleTimerDisabled to true.

For this reason, be sure to use the dispose method of StatefulWidget etc.

KeepScreenOn.turnOff();

Should be called. If you forget to call turnOff (or turnOn(false)), the screen will not turn off automatically while the app is running.

For Android, when the activity is switched, the automatic screen off will follow the activity to which it was switched.
For iOS, automatic screen off is restored when you move to the background.

flutter_keep_screen_on's People

Contributors

lynrin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.