远程遥控相关

This commit is contained in:
2026-11-06 08:34:19 +08:00
parent eb8dec2868
commit d882db7995
42 changed files with 5023 additions and 631 deletions

View File

@@ -7,6 +7,11 @@ class CapsuleToast {
static OverlayEntry? _entry;
static bool _showing = false;
/// 弹出代数:每次真正插入新胶囊时递增。
/// 自动消失的定时器只允许关闭「自己这一代」的胶囊,
/// 否则旧提示的定时器会把后弹的新提示提前移除(连点时新 toast 一闪即没)。
static int _generation = 0;
/// 显示胶囊提示
/// [message] 提示文案
/// [duration] 显示时长,默认 2 秒
@@ -49,6 +54,7 @@ class CapsuleToast {
_entry?.remove();
_showing = false;
}
final int gen = ++_generation;
_entry = OverlayEntry(
builder: (context) => IgnorePointer(
@@ -56,7 +62,8 @@ class CapsuleToast {
child: Align(
alignment: Alignment.topCenter,
child: Container(
margin: const EdgeInsets.only(top: 64),
// 左右留白:英文文案明显长于中文,限制胶囊最大宽度避免贴边溢出
margin: const EdgeInsets.only(top: 64, left: 24, right: 24),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: const Color(0xE62C2C2C),
@@ -80,12 +87,18 @@ class CapsuleToast {
),
const SizedBox(width: 6),
],
Text(
message,
style: const TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.w500,
// 长文案(尤其英文)需要可收缩并换行,否则 Row 会横向溢出
Flexible(
child: Text(
message,
maxLines: 3,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.w500,
),
),
),
],
@@ -100,6 +113,8 @@ class CapsuleToast {
_showing = true;
Future.delayed(duration, () {
// 期间已弹出过更新的提示 → 本定时器属于旧一代,不能误杀新胶囊
if (gen != _generation) return;
if (_showing) {
_entry?.remove();
_showing = false;