搜尋套件、儲存庫與 APP 分類

套件詳情v7.0.0

keep_screen_on

此外掛程式停用自動螢幕關閉,並防止螢幕關閉。

AndroidiOS
近 30 天下載
3萬
喜歡數
54
Pub 分數
160

安裝套件

flutter pub add keep_screen_on

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

keep_screen_on 套件可防止裝置螢幕自動關閉,確保顯示持續可見。它非常適合需要不斷螢幕活動的應用程式,例如影片播放器、導航應用程式或看板模式。此套件適用於 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

原始碼儲存庫

使用此套件的專案

暫無相關資料。