新版UI-登录页面-我的页面(简单适配)-设备的部分(无设备的+有设备)

This commit is contained in:
2026-10-24 09:08:33 +08:00
parent 81dae187ac
commit e3af8cf617
19 changed files with 4848 additions and 51 deletions

View File

@@ -35,6 +35,7 @@ import 'drone_station_detail_page.dart';
import '../../../../../core/network/mqtt/data/datasources/drone_osd_datasource.dart';
import 'qr_scanner_page.dart';
import 'bind_device_page.dart';
import 'no_device_page_v2.dart';
import '../../../local_camera/presentation/pages/local_camera_page.dart';
import '../../../usb_camera/presentation/pages/usb_camera_page.dart';
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
@@ -190,50 +191,70 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
// 无设备时整页是固定浅色渐变(与我的页 V2 同款),状态栏图标须恒为深色;
// 若跟随深色主题给白色图标,会消失在浅蓝背景上。
final isNoDevice = _isNoDeviceState(
context.watch<DeviceListBloc.DeviceStatusBloc>().state,
);
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: isDark ? Brightness.light : Brightness.dark,
statusBarIconBrightness: isNoDevice
? Brightness.dark
: (Theme.of(context).brightness == Brightness.dark
? Brightness.light
: Brightness.dark),
),
child: Scaffold(
backgroundColor: context.appColors.pageBackground,
body: SafeArea(
child:
BlocConsumer<
DeviceListBloc.DeviceStatusBloc,
DeviceListState.DeviceStatusState
>(
listener: (context, state) {
// 🔥 监听错误状态,显示友好提示
if (state is DeviceListState.DeviceStatusError &&
state.shouldShowError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
backgroundColor: context.appColors.warning,
),
);
}
},
builder: (context, state) {
return Column(
children: [
_buildAppBar(context),
_buildSearchBar(context),
_buildTypeFilterBar(context),
Expanded(child: _buildContent(context, state)),
],
);
},
// SafeArea 下移到常规列表分支:无设备页渐变需铺进状态栏(与我的页一致)
body: BlocConsumer<
DeviceListBloc.DeviceStatusBloc,
DeviceListState.DeviceStatusState
>(
listener: (context, state) {
// 🔥 监听错误状态,显示友好提示
if (state is DeviceListState.DeviceStatusError &&
state.shouldShowError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
backgroundColor: context.appColors.warning,
),
);
}
},
builder: (context, state) {
// 无设备:该场站设备接口返回空时,整页(含顶栏)切换到
// 「01_无设备首页」设计稿页面;逻辑链保持 场站→siteId→设备列表 不变。
if (_isNoDeviceState(state)) {
return const NoDevicePageV2();
}
return SafeArea(
child: Column(
children: [
_buildAppBar(context),
_buildSearchBar(context),
_buildTypeFilterBar(context),
Expanded(child: _buildContent(context, state)),
],
),
);
},
),
),
);
}
/// 无设备判据:「全部」标签下设备接口返回空
bool _isNoDeviceState(DeviceListState.DeviceStatusState state) {
return state is DeviceListState.DeviceStatusLoaded &&
state.selectedType == 'all' &&
state.devices.isEmpty;
}
Widget _buildAppBar(BuildContext context) {
// 🔥 个人角色(roleKey == 'personal')隐藏场站选择器
final roleKey = context.watch<AppUserCubit>().state.user?.roleKey;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,575 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
import 'package:maibu_satabot_v2/features/main_container/domain/tab_config.dart';
import 'package:maibu_satabot_v2/features/v2/local_camera/presentation/pages/local_camera_page.dart';
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/usb_camera/presentation/pages/usb_camera_page.dart';
import '../bloc/device_status_bloc.dart';
import '../bloc/device_status_event.dart';
import 'bind_device_page.dart';
import 'qr_scanner_page.dart';
/// 无设备首页 —— 按「01_无设备首页」设计稿实现。
///
/// 触发条件(逻辑链不变):SiteCubit 取所有场站 → 第一个场站拉设备列表 →
/// DeviceStatusLoaded 且 devices 为空时,由 DeviceStatusView 整页切换到本页。
///
/// 说明:
/// - 顶栏按设计稿换新:SATA logo + 铃铛/⊕ 白底按钮;
/// - 右上角按钮下方小字「(场站名)」为切换场站入口,个人角色追加「个人账号」说明;
/// - 「添加机器人」与卡片蓝色 ⊕ 均弹出底部添加弹窗,内部各项保持原跳转;
/// - 「新手入门」三条二级内容未开发,统一 Toast 提示;
/// - 背景用设计稿地图背景切图 shebei_bg.png,车图为透明底 shebei-logo.png,
/// 车与背景分层不粘连。
class NoDevicePageV2 extends StatelessWidget {
const NoDevicePageV2({super.key});
// ===== 固定视觉配色(与登录页/我的页 V2 同系) =====
static const _bgTop = Color(0xFFFAFCFF);
static const _navy = Color(0xFF1A2B4A);
static const _grayText = Color(0xFF86909C);
static const _primaryBlue = Color(0xFF1C96F6);
static const _cardBorder = Color(0xFFE9F1FA);
static const _btnGradient = LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Color(0xFF2BAFFE), Color(0xFF1C96F6), Color(0xFF0B7DEE)],
stops: [0.0, 0.5, 1.0],
);
static void _todoTap() {
CapsuleToast.show('功能暂未开发', showCheck: false);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: _bgTop,
body: Stack(
fit: StackFit.expand,
children: [
// 背景:设计稿地图背景切图,顶对齐裁切(替代此前手绘三层渐变)
Positioned.fill(
child: Image.asset(
'assets/images/shebei_bg.png',
fit: BoxFit.cover,
alignment: Alignment.topCenter,
),
),
SafeArea(
bottom: false,
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 8),
_buildTopBar(context),
_buildSiteEntry(context),
const SizedBox(height: 18),
_buildHeroCard(context),
const SizedBox(height: 26),
const Center(
child: Text(
'还没有添加机器人',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: _navy,
),
),
),
const SizedBox(height: 10),
const Center(
child: Text(
'您可以先了解 APP 的功能,\n收到机器人后随时绑定使用。',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 13,
color: _grayText,
height: 1.6,
),
),
),
const SizedBox(height: 20),
_buildAddButton(context),
const SizedBox(height: 30),
const Text(
'新手入门',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _navy,
),
),
const SizedBox(height: 12),
_buildGuideCard(
icon: Icons.list_alt,
title: '产品操作指南',
subtitle: '了解机器人基础功能和使用流程',
),
const SizedBox(height: 10),
_buildGuideCard(
icon: Icons.videocam_outlined,
title: '观看产品视频',
subtitle: '快速上手遥控、图传及作业功能',
),
const SizedBox(height: 10),
_buildGuideCard(
icon: Icons.help_outline,
title: '帮助与售后服务',
subtitle: '常见问题、报修及客服支持',
),
const SizedBox(height: 24),
],
),
),
),
],
),
);
}
// ===== 顶栏:logo + 铃铛/⊕(设计稿新样式) =====
Widget _buildTopBar(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset(
'assets/images/me_left_logo.png',
height: 44,
fit: BoxFit.contain,
),
Row(
children: [
_buildTopIconButton(Icons.notifications_none, onTap: _todoTap),
const SizedBox(width: 10),
// 设计稿:右上角 ⊕ 是蓝底白号主色按钮,与铃铛的白底按钮区分
_buildTopIconButton(
Icons.add,
onTap: () => _showAddSheet(context),
primary: true,
),
],
),
],
);
}
Widget _buildTopIconButton(
IconData icon, {
required VoidCallback onTap,
bool primary = false,
}) {
return GestureDetector(
onTap: onTap,
child: Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: primary ? null : Colors.white,
gradient: primary ? _btnGradient : null,
borderRadius: BorderRadius.circular(14),
border: primary ? null : Border.all(color: _cardBorder),
boxShadow: [
BoxShadow(
color: primary
? _primaryBlue.withValues(alpha: 0.3)
: _primaryBlue.withValues(alpha: 0.05),
blurRadius: primary ? 10 : 8,
offset: const Offset(0, 2),
),
],
),
child: Icon(
icon,
size: 22,
color: primary ? Colors.white : _navy,
),
),
);
}
// ===== 切换场站入口:右上角按钮下方小字(场站名) =====
Widget _buildSiteEntry(BuildContext context) {
final isPersonal =
context.watch<AppUserCubit>().state.user?.roleKey ==
TabConfig.personalRoleKey;
return BlocBuilder<SiteCubit, SiteState>(
bloc: GetIt.I<SiteCubit>(),
builder: (context, siteState) {
final name = siteState.selectedSite?.siteName ?? '未选择场站';
return Align(
alignment: Alignment.centerRight,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _onSiteTap(context, siteState, isPersonal),
child: Padding(
padding: const EdgeInsets.only(top: 6, right: 4, bottom: 4),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
isPersonal ? '($name)· 个人账号' : '($name)',
style: const TextStyle(fontSize: 12, color: _grayText),
),
if (!isPersonal)
const Icon(
Icons.keyboard_arrow_down,
size: 16,
color: _grayText,
),
],
),
),
),
);
},
);
}
void _onSiteTap(BuildContext context, SiteState siteState, bool isPersonal) {
if (isPersonal) {
CapsuleToast.show('个人账号仅绑定一个场站', showCheck: false);
return;
}
if (siteState.sites.isEmpty) {
CapsuleToast.show('暂无场站数据', showCheck: false);
return;
}
final siteCubit = GetIt.I<SiteCubit>();
showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (sheetCtx) {
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Padding(
padding: EdgeInsets.symmetric(vertical: 14),
child: Center(
child: Text(
'选择场站',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _navy,
),
),
),
),
const Divider(height: 1, color: Color(0xFFF0F4FA)),
Flexible(
child: ListView.builder(
shrinkWrap: true,
itemCount: siteState.sites.length,
itemBuilder: (_, i) {
final site = siteState.sites[i];
final selected =
siteCubit.state.selectedSite?.id == site.id;
return ListTile(
title: Text(
site.siteName,
style: TextStyle(
fontSize: 15,
fontWeight: selected
? FontWeight.w600
: FontWeight.w400,
color: selected ? _primaryBlue : _navy,
),
),
trailing: selected
? const Icon(
Icons.check,
size: 20,
color: _primaryBlue,
)
: null,
onTap: () {
// 选中后 SiteCubit 流会触发设备列表重拉;
// 若新场站有设备,本页会自动退回正常列表。
siteCubit.selectSite(site);
Navigator.pop(sheetCtx);
},
);
},
),
),
],
),
);
},
);
}
// ===== Hero 卡:透明底车图 + 右上角蓝色 ⊕ =====
Widget _buildHeroCard(BuildContext context) {
return Container(
height: 230,
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.72),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: _cardBorder),
boxShadow: [
BoxShadow(
color: _primaryBlue.withValues(alpha: 0.06),
blurRadius: 16,
offset: const Offset(0, 4),
),
],
),
child: Stack(
children: [
Positioned.fill(
child: Padding(
padding: const EdgeInsets.all(20),
child: Image.asset(
'assets/images/shebei-logo.png',
fit: BoxFit.contain,
),
),
),
Positioned(
top: 14,
right: 14,
child: GestureDetector(
onTap: () => _showAddSheet(context),
child: Container(
width: 40,
height: 40,
decoration: const BoxDecoration(
shape: BoxShape.circle,
gradient: _btnGradient,
),
child: const Icon(Icons.add, color: Colors.white, size: 22),
),
),
),
],
),
);
}
// ===== 添加机器人主按钮 =====
Widget _buildAddButton(BuildContext context) {
return GestureDetector(
onTap: () => _showAddSheet(context),
child: Container(
height: 48,
decoration: BoxDecoration(
gradient: _btnGradient,
borderRadius: BorderRadius.circular(14),
boxShadow: [
BoxShadow(
color: _primaryBlue.withValues(alpha: 0.3),
blurRadius: 12,
offset: const Offset(0, 4),
),
],
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add, color: Colors.white, size: 20),
SizedBox(width: 8),
Text(
'添加机器人',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
],
),
),
);
}
// ===== 添加机器人底部弹窗:各项保持原跳转 =====
void _showAddSheet(BuildContext context) {
showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (sheetCtx) {
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 14, 8, 4),
child: Row(
children: [
const Expanded(
child: Center(
child: Text(
'添加机器人',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _navy,
),
),
),
),
IconButton(
icon: const Icon(
Icons.close,
size: 20,
color: _grayText,
),
onPressed: () => Navigator.pop(sheetCtx),
),
],
),
),
_sheetItem(
icon: Icons.qr_code_scanner,
label: '扫一扫',
onTap: () async {
Navigator.pop(sheetCtx);
final result = await Navigator.of(context).push<String>(
MaterialPageRoute(builder: (_) => const QrScannerPage()),
);
if (result != null && context.mounted) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => BindDevicePage(scanResult: result),
),
);
// 绑定流程结束后重拉设备列表,有设备则自动退回正常列表页
if (context.mounted) {
context.read<DeviceStatusBloc>().add(
const DeviceStatusRefresh(),
);
}
}
},
),
_sheetDivider(),
_sheetItem(
icon: Icons.add_circle_outline,
label: '添加设备',
onTap: () {
Navigator.pop(sheetCtx);
// 原菜单该项即为 TODO,保持不跳转
_todoTap();
},
),
_sheetDivider(),
_sheetItem(
icon: Icons.videocam_outlined,
label: '本地视频',
onTap: () {
Navigator.pop(sheetCtx);
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const LocalCameraPage()),
);
},
),
_sheetDivider(),
_sheetItem(
icon: Icons.usb,
label: 'USB 摄像头',
onTap: () {
Navigator.pop(sheetCtx);
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const UsbCameraPage()),
);
},
),
const SizedBox(height: 8),
],
),
);
},
);
}
Widget _sheetItem({
required IconData icon,
required String label,
required VoidCallback onTap,
}) {
return InkWell(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
child: Row(
children: [
Icon(icon, size: 20, color: _navy),
const SizedBox(width: 12),
Text(
label,
style: const TextStyle(fontSize: 15, color: _navy),
),
],
),
),
);
}
Widget _sheetDivider() {
return const Divider(height: 1, indent: 20, color: Color(0xFFF0F4FA));
}
// ===== 新手入门卡片:二级未开发,统一提示 =====
Widget _buildGuideCard({
required IconData icon,
required String title,
required String subtitle,
}) {
return GestureDetector(
onTap: _todoTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: _cardBorder),
),
child: Row(
children: [
Icon(icon, size: 24, color: _primaryBlue),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: _navy,
),
),
const SizedBox(height: 3),
Text(
subtitle,
style: const TextStyle(fontSize: 12, color: _grayText),
),
],
),
),
const Icon(
Icons.chevron_right,
size: 20,
color: Color(0xFFC9CDD4),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,344 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
/// 设备状态 V2 —— 卡片视图设计稿组件。
///
/// 纯展示组件:点击回调、在线状态、电量均由页面传入真实数据
/// (在线态来自 onlineStatus,电量来自 battery / capacityPercent,与旧卡片一致)。
/// 仅版本 / SN 掩码等后端暂未返回的字段用设备 ID 做**稳定伪随机**占位
/// (同一设备每次渲染结果一致,不会闪变),等后端补齐字段后替换为真值即可。
/// 设备展示状态(对应设计稿徽章:作业中 / 在线 / 离线)
enum DeviceV2Status { working, online, offline }
/// 占位数据生成器:以设备唯一串为种子,保证同设备结果稳定
class DeviceV2Display {
DeviceV2Display._();
static const _editions = ['PLUS 智能版', 'STD 标准版', 'PRO 旗舰版'];
static int _seed(String key) => key.hashCode & 0x7FFFFFFF;
/// 版本后缀:PLUS 智能版 / STD 标准版 / PRO 旗舰版
static String editionOf(String key) => _editions[_seed(key) % _editions.length];
/// SN 掩码展示:前4 · · · 后2
static String maskedSn(String key) {
if (key.length <= 6) return key.toUpperCase();
return '${key.substring(0, 4)} · · · ${key.substring(key.length - 2)}'
.toUpperCase();
}
/// 底部作业态文案
static String workTextOf(DeviceV2Status status) {
return switch (status) {
DeviceV2Status.working => '自主作业中',
DeviceV2Status.online => '待机',
DeviceV2Status.offline => '暂时无法连接',
};
}
}
/// 设计稿设备卡片:缩略图 + 名称/徽章 + 型号版本 + SN + 底部作业态/电量
class DeviceCardV2 extends StatelessWidget {
const DeviceCardV2({
super.key,
required this.name,
required this.modelText,
required this.snKey,
required this.status,
required this.onTap,
this.batteryLevel,
});
/// 设备名称(别名优先,页面已处理)
final String name;
/// 型号 · 版本,如 "MC700 · PLUS 智能版"
final String modelText;
/// 用于 SN 掩码/复制与占位随机的设备唯一串
final String snKey;
final DeviceV2Status status;
/// 真实电量百分比(离线或无数据时传 null,卡片显示 --)
final int? batteryLevel;
/// 卡片点击:与旧卡片同一跳转逻辑
final VoidCallback onTap;
// ===== 固定视觉配色(与登录/我的/无设备页 V2 同系) =====
static const _navy = Color(0xFF1A2B4A);
static const _grayText = Color(0xFF86909C);
static const _primaryBlue = Color(0xFF1C96F6);
static const _cardBorder = Color(0xFFE9F1FA);
static const _workingOrange = Color(0xFFF5A623);
static const _workingBg = Color(0xFFFEF3E3);
static const _onlineGreen = Color(0xFF2FBF6B);
static const _onlineBg = Color(0xFFE5F8EC);
static const _offlineGray = Color(0xFF6B7280);
static const _offlineBg = Color(0xFFF0F2F5);
@override
Widget build(BuildContext context) {
final offline = status == DeviceV2Status.offline;
final battery = offline ? null : batteryLevel;
return GestureDetector(
onTap: onTap,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: _cardBorder),
boxShadow: [
BoxShadow(
color: _primaryBlue.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
padding: const EdgeInsets.all(12),
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildThumb(offline),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Flexible(
child: Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: _navy,
),
),
),
// 编辑(改名):后端能力未接,统一提示
GestureDetector(
onTap: () =>
CapsuleToast.show('功能暂未开发', showCheck: false),
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 6),
child: Icon(
Icons.edit_outlined,
size: 15,
color: _grayText,
),
),
),
_buildBadge(),
],
),
const SizedBox(height: 6),
Text(
modelText,
style: const TextStyle(fontSize: 13, color: _grayText),
),
const SizedBox(height: 6),
Row(
children: [
Flexible(
child: Text(
'SN: ${DeviceV2Display.maskedSn(snKey)}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 13,
color: _grayText,
),
),
),
// 复制完整 SN
GestureDetector(
onTap: () async {
await Clipboard.setData(
ClipboardData(text: snKey),
);
CapsuleToast.show('SN 已复制到剪贴板');
},
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 6),
child: Icon(
Icons.copy_rounded,
size: 15,
color: _grayText,
),
),
),
],
),
],
),
),
Column(
children: [
// 更多操作:二级未开发
GestureDetector(
onTap: () =>
CapsuleToast.show('功能暂未开发', showCheck: false),
child: Container(
width: 32,
height: 32,
decoration: BoxDecoration(
color: const Color(0xFFF3F6FA),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(
Icons.more_horiz,
size: 18,
color: _navy,
),
),
),
const SizedBox(height: 14),
const Icon(
Icons.chevron_right,
size: 20,
color: Color(0xFFC9CDD4),
),
],
),
],
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 10),
child: Divider(height: 1, color: Color(0xFFF0F4FA)),
),
Row(
children: [
Icon(
offline
? Icons.link_off
: Icons.monitor_heart_outlined,
size: 18,
color: offline ? _offlineGray : _primaryBlue,
),
const SizedBox(width: 6),
Text(
DeviceV2Display.workTextOf(status),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: offline ? _offlineGray : _navy,
),
),
const Icon(
Icons.keyboard_arrow_right,
size: 16,
color: Color(0xFFC9CDD4),
),
const Spacer(),
_buildBattery(battery),
],
),
],
),
),
);
}
/// 缩略图:透明底车图,离线时置灰
Widget _buildThumb(bool offline) {
return Container(
width: 96,
height: 78,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFFEAF3FE), Color(0xFFD9EAFB)],
),
),
child: () {
final car = Image.asset(
'assets/images/shebei-logo.png',
fit: BoxFit.cover,
);
// 离线置灰;在线不能套任何滤镜(transparent 滤镜会把图洗没)
if (!offline) return car;
return ColorFiltered(
colorFilter: const ColorFilter.matrix(<double>[
0.33, 0.33, 0.33, 0, 40, //
0.33, 0.33, 0.33, 0, 40, //
0.33, 0.33, 0.33, 0, 40, //
0, 0, 0, 1, 0, //
]),
child: car,
);
}(),
);
}
/// 状态徽章:作业中(橙) / 在线(绿) / 离线(灰)
Widget _buildBadge() {
final (color, bg, label) = switch (status) {
DeviceV2Status.working => (_workingOrange, _workingBg, '作业中'),
DeviceV2Status.online => (_onlineGreen, _onlineBg, '在线'),
DeviceV2Status.offline => (_offlineGray, _offlineBg, '离线'),
};
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(20)),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 5,
height: 5,
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
),
const SizedBox(width: 4),
Text(
label,
style: TextStyle(fontSize: 11, fontWeight: FontWeight.w600, color: color),
),
],
),
);
}
/// 电量:离线显示空电池 + --
Widget _buildBattery(int? level) {
if (level == null) {
return const Row(
children: [
Icon(Icons.battery_unknown, size: 18, color: _offlineGray),
SizedBox(width: 4),
Text('--', style: TextStyle(fontSize: 13, color: _offlineGray)),
],
);
}
final icon = switch (level) {
>= 80 => Icons.battery_full,
>= 50 => Icons.battery_5_bar,
>= 25 => Icons.battery_3_bar,
_ => Icons.battery_2_bar,
};
return Row(
children: [
Icon(icon, size: 18, color: _onlineGreen),
const SizedBox(width: 4),
Text(
'$level%',
style: const TextStyle(fontSize: 13, color: _navy),
),
],
);
}
}