远程遥控开发中
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/widgets/status_chip.dart';
|
||||
|
||||
import '../../../devices/presentation/bloc/devices_cubit.dart';
|
||||
@@ -23,7 +25,7 @@ class TopStatusBar extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
// 1. 返回按钮 (对应 SimpleSmallFunctionButton)
|
||||
_buildIconButton(Icons.arrow_back_ios_new, () => context.pop()),
|
||||
_buildIconButton("assets/svgs/remote_back.svg", () => context.pop()),
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// 2. 控制状态 (对应 StatusChipLeft)
|
||||
@@ -45,38 +47,47 @@ class TopStatusBar extends StatelessWidget {
|
||||
|
||||
// 3. 锁定状态 (对应 SmallFunctionButton)
|
||||
_buildIconButton(
|
||||
remoteState.isLocked ? Icons.lock : Icons.lock_open,
|
||||
remoteState.isLocked
|
||||
? "assets/svgs/remote_lock.svg"
|
||||
: "assets/svgs/remote_lock_open.svg",
|
||||
() => context.read<RemoteControlCubit>().toggleLock(),
|
||||
isSelected: remoteState.isLocked,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 4. 刷新按钮
|
||||
_buildIconButton(Icons.refresh, () {
|
||||
// 刷新 WebView 逻辑
|
||||
}),
|
||||
_buildIconButton("assets/svgs/remote_refresh.svg", () {}),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// TODO
|
||||
_buildControlModeChip(,remoteState.runningStatusModel.controlMode),
|
||||
|
||||
const SizedBox(width: 8),
|
||||
|
||||
_buildVoltageChip(remoteState.voltage),
|
||||
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 5. 信号延迟 (对应 pingStatusChip)
|
||||
_buildPingChip(remoteState.ping),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 6. 电量 (对应 StatusChipRight)
|
||||
_buildBatteryChip(remoteState?.battery ?? 0),
|
||||
_buildBatteryChip(remoteState.battery),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 对应 Android 里的 SimpleSmallFunctionButton 样式
|
||||
Widget _buildIconButton(
|
||||
IconData icon,
|
||||
String svgAsset, // 改为 String 路径,例如 'assets/icons/stop.svg'
|
||||
VoidCallback onTap, {
|
||||
bool isSelected = false,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
@@ -87,7 +98,12 @@ class TopStatusBar extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.3), width: 0.5),
|
||||
),
|
||||
child: Icon(icon, color: Colors.white, size: 18),
|
||||
padding: const EdgeInsets.all(7),
|
||||
child: SvgPicture.asset(
|
||||
svgAsset,
|
||||
// 这里可以使用 colorFilter 来改变 SVG 的颜色(如果需要根据选中状态变色)
|
||||
colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -98,18 +114,81 @@ class TopStatusBar extends StatelessWidget {
|
||||
: (ping < 200 ? Colors.orange : Colors.red);
|
||||
return StatusChip(
|
||||
text: "$ping ms",
|
||||
color: color,
|
||||
color: color.withValues(alpha: 0.6),
|
||||
svgColor: color,
|
||||
icon: Icons.network_check,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildControlModeChip(ControlMode mode) {
|
||||
String displayText;
|
||||
switch (mode) {
|
||||
case ControlMode.BLE:
|
||||
displayText = '蓝牙模式';
|
||||
break;
|
||||
case ControlMode.LOCAL:
|
||||
displayText = '本地模式';
|
||||
break;
|
||||
case ControlMode.TCP:
|
||||
displayText = 'TCP模式';
|
||||
break;
|
||||
case ControlMode.NONE:
|
||||
displayText = '无模式';
|
||||
break;
|
||||
case ControlMode.OTHER:
|
||||
displayText = '其他模式';
|
||||
break;
|
||||
default:
|
||||
displayText = '未知模式';
|
||||
}
|
||||
|
||||
return StatusChip(
|
||||
text: displayText,
|
||||
color: Colors.blue.withValues(alpha: 0.6),
|
||||
svgColor: Colors.blue,
|
||||
svgPath: "assets/svgs/remote_net.svg",
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildVoltageChip(int voltage) {
|
||||
return StatusChip(
|
||||
text: "$voltage V",
|
||||
color: Color(0xFFFACC15).withValues(alpha: 0.6),
|
||||
svgColor: Color(0xFFFACC15),
|
||||
svgPath: "assets/svgs/remote_zap.svg",
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBatteryChip(int level) {
|
||||
IconData icon = level > 80
|
||||
? Icons.battery_full
|
||||
: (level > 20 ? Icons.battery_3_bar : Icons.battery_alert);
|
||||
Color color = level > 80
|
||||
? Colors.green
|
||||
: (level > 30 ? Colors.orange : Colors.red);
|
||||
return StatusChip(text: "$level%", color: color, icon: icon);
|
||||
// 1. 根据数值判断图片路径 (逻辑与之前一致)
|
||||
String svgPath;
|
||||
Color color;
|
||||
|
||||
if (level >= 90) {
|
||||
svgPath = "assets/svgs/remote_battery_full.svg";
|
||||
color = Colors.green;
|
||||
} else if (level >= 50) {
|
||||
svgPath = "assets/svgs/remote_battery_middle.svg";
|
||||
color = Colors.greenAccent;
|
||||
} else if (level >= 20) {
|
||||
svgPath = "assets/svgs/remote_battery_low.svg";
|
||||
color = Colors.orange;
|
||||
} else if (level >= 10) {
|
||||
svgPath = "assets/svgs/remote_battery_warning.svg";
|
||||
color = Colors.redAccent;
|
||||
} else {
|
||||
svgPath = "assets/svgs/remote_battery_none.svg";
|
||||
color = Colors.red;
|
||||
}
|
||||
|
||||
// 2. 使用 StatusChip 包装,但 icon 传入 SvgPicture
|
||||
return StatusChip(
|
||||
text: "$level%",
|
||||
color: color.withValues(alpha: 0.6),
|
||||
svgColor: color,
|
||||
// 如果你的 StatusChip 已经改为接受 Widget,则直接传 SvgPicture
|
||||
// 如果 StatusChip 目前只接受 IconData,你需要按我之前的建议给它加个 leading 参数
|
||||
svgPath: svgPath,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user