远程遥控相关

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;

View File

@@ -0,0 +1,56 @@
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
/// 控制模式(`RunningStatusEntity.controlMode`)→ 界面文案的唯一映射。
///
/// 为什么要单独一个文件:这个值以前在 7 个页面各写一遍「== 3 ? 远程 : 本地」,
/// 而数据层又把「后端没给」的默认值写成 `'0'`,两个错误叠在一起,结果是
/// 设备从来没上报过控制模式时,界面一本正经地显示「本地控制」——假信号。
///
/// 协议定义(2026-11 后端重新确认,覆盖早先「0=无控制 / 2=蓝牙 / 4=其他接口」那版):
/// 空串 / null → 「未知」:后端根本没给这个字段
/// 0 → 未知
/// 1 → 本地控制
/// 2 → 自主任务
/// 3 → 远程控制(远程遥控)
/// 其它数字 → 「未知(6)」:协议外的值,不猜它是什么意思
/// 非数字字符串 → 原样显示:后端给什么展示什么
///
/// [controlModeKey] 只返回已定义的 0~4,其余为 null,供各页面沿用本页的
/// 翻译器与自定义文案接;需要一步拿到最终文本用 [controlModeDisplayText]。
/// 已定义的协议值 → 多语言 key;空值、非数字、协议外数字返回 null。
String? controlModeKey(String? raw) {
final int? n = controlModeValue(raw);
if (n == null) return null;
return switch (n) {
0 => 'common.unknown',
1 => 'running_status.local_control',
2 => 'running_status.autonomous_task',
3 => 'running_status.remote_control',
_ => null,
};
}
/// 原始值 → 协议数值。空串/非数字返回 null,表示「没有可信的控制模式数据」。
int? controlModeValue(String? raw) {
final String v = (raw ?? '').trim();
if (v.isEmpty) return null;
return int.tryParse(v);
}
/// 直接得到可显示文案(含未知/协议外/非数字的兜底)。
String controlModeDisplayText(AppLocalizations l10n, String? raw) {
final String? key = controlModeKey(raw);
if (key != null) return l10n.translate(key);
final String v = (raw ?? '').trim();
if (v.isEmpty) return l10n.translate('common.unknown');
final int? n = int.tryParse(v);
// 协议外的数字:带上原值,现场排查时能看出后端到底发了什么
if (n != null) {
return '${l10n.translate('common.unknown')}($n)';
}
// 后端给的不是数字:按它给的显示,不做任何猜测
return v;
}