Feature Request: Add Custom Duration for Keeping the Screen Awake

未关闭
#153 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
dart, flutter
领域
mobile

调研方向

Start by reading the implementation of WakelockPlus.enable() and its platform interfaces to see how wake lock requests are handled across Android, iOS, macOS, Windows, Linux, and web. Check the existing tests for enable and disable behavior, then trace how a duration could be applied consistently. Done means an optional duration automatically disables the wake lock, while manual disable and indefinite enable continue to work.

由索引模型根据 Issue 内容生成。

描述

It would be useful to support a custom duration when enabling the wake lock.

Currently, wakelock_plus allows keeping the screen awake indefinitely until WakelockPlus.disable() is called. However, there are use cases where developers only need to keep the screen on for a specific period.

I suggest introducing an optional duration parameter that automatically disables the wake lock after the specified time.

Proposed API

// Keep screen awake for 1 minute.
WakelockPlus.enable(
duration: const Duration(minutes: 1),
);

// Keep screen awake for 2 minutes.
WakelockPlus.enable(
duration: const Duration(minutes: 2),
);

// Keep screen awake indefinitely (current behavior).
WakelockPlus.enable();

Expected Behavior

Accept an optional Duration parameter when enabling the wake lock.

Automatically disable the wake lock when the specified duration expires.

If no duration is provided, preserve the current behavior (keep the screen awake until manually disabled).

Calling disable() manually should still work before the duration expires.

Use Case

For example, in reading or memorization applications, developers may want to prevent the screen from turning off while the user is actively reading, but only for a limited period (e.g., 1 or 2 minutes), without implementing their own timer and manually managing the wake lock lifecycle.

This would make the package more flexible and reduce the need for additional timer logic in applications.

主要语言
Dart
星标
110
派生
100
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fluttercommunity/wakelock_plus 的其他 Issue

查看 fluttercommunity/wakelock_plus 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。