搜索插件、代码仓与 APP 分类

插件详情v7.0.0

keep_screen_on

此插件禁用自动屏幕关闭,并防止屏幕关闭。

AndroidiOS
近 30 天下载
3万
喜欢数
54
Pub 分数
160

安装插件

flutter pub add keep_screen_on

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

keep_screen_on 包可防止设备屏幕自动关闭,确保显示持续可见。它非常适合需要不间断屏幕活动的应用程序,例如视频播放器、导航应用或 kiosk 模式。该包适用于 Android 和 iOS,可通过简单的添加命令与 Flutter 项目无缝集成。该插件通过在设备上保持唤醒锁来工作,维持屏幕亮度和活动状态。它轻量且设计简洁,无需复杂配置即可轻松实现。

适合场景

  • 视频播放
  • 导航应用
  • 自助服务模式
  • 演示工具
  • 长时间运行的任务

主要特点

  • 防止自动屏幕变暗
  • 跨平台(Android & iOS)
  • 简单集成
  • 最小配置
  • 唤醒锁管理

适合对象

  • 媒体应用
  • 交互式显示
  • 现场服务工具
  • 数字标牌
  • 时间敏感的工作流程

使用建议

  • 电池消耗增加
  • 某些设备需要用户权限
  • 不适用于后台操作
  • 可能与系统省电功能冲突
  • 屏幕亮度控制有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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: ^6.0.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(on: 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 <bool?>, 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;
}
Android only.

The following functions are available on Android. Nothing happens even if you run it on an OS other than Android.

You can specify the withAllowLockWhileScreenOn argument to the turnOn and turnOff methods.
When withAllowLockWhileScreenOn: true is specified, FLAG_ALLOW_LOCK_WHILE_SCREEN_ON is also specified in addition to FLAG_KEEP_SCREEN_ON.

KeepScreenOn.turnOn(withAllowLockWhileScreenOn: true);

KeepScreenOn.turnOff(withAllowLockWhileScreenOn: true);

If you want to switch only FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, you can do so by calling the method below.

KeepScreenOn.addAllowLockWhileScreenOn();

KeepScreenOn.clearAllowLockWhileScreenOn();

You can check the assignment status of FLAG_ALLOW_LOCK_WHILE_SCREEN_ON from the isAllowLockWhileScreenOn property.

KeepScreenOn.isAllowLockWhileScreenOn

Each call returns the following values on non-Android OS:

Method/Property Returns
addAllowLockWhileScreenOn false
clearAllowLockWhileScreenOn false
isAllowLockWhileScreenOn null

Attention

When you call the turnOn method with no arguments or with on: 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(on: 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.

所属分类

依赖

依赖清单 1 项

  • keep_screen_on_platform_interface^3.0.0

源码仓库

使用此插件的项目

暂无相关数据。