绑定页新UI+逻辑链路的适配+设备的首页无设备页面和详情页面

This commit is contained in:
2026-10-24 17:18:42 +08:00
parent e3af8cf617
commit 8a41113c92
10 changed files with 2931 additions and 105 deletions

View File

@@ -0,0 +1,524 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:maibu_satabot_v2/core/di/injection.dart';
import '../cubit/bind_device_cubit.dart';
import '../cubit/bind_device_state.dart';
/// 绑定流程第三环节「绑定激活」页 V2。
///
/// 复制自旧 BindDevicePage(扫码后跳转的那个页):逻辑完全保留——
/// 组织/场站/负责人级联下拉、角色必填规则、submitBind(scanResult)、
/// 成功/失败 SnackBar 提示与回退;仅 UI 换成 V2 浅色风格。
/// 旧页 BindDevicePage 不删除,旧版页面仍挂旧页。
class BindActivatePageV2 extends StatefulWidget {
final String scanResult;
const BindActivatePageV2({super.key, required this.scanResult});
@override
State<BindActivatePageV2> createState() => _BindActivatePageV2State();
}
class _BindActivatePageV2State extends State<BindActivatePageV2> {
static const _navy = Color(0xFF1A2B4A);
static const _gray = Color(0xFF86909C);
static const _blue = Color(0xFF1C96F6);
static const _green = Color(0xFF2FBF6B);
static const _border = Color(0xFFE5EDF7);
static const _fill = Color(0xFFF5F7FA);
static const _btnGradient = LinearGradient(
colors: [Color(0xFF2BAFFE), Color(0xFF1C96F6), Color(0xFF0B7DEE)],
);
late final BindDeviceCubit _cubit;
@override
void initState() {
super.initState();
_cubit = sl<BindDeviceCubit>();
_cubit.init();
}
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => _cubit,
child: BlocListener<BindDeviceCubit, BindDeviceState>(
listener: (context, state) {
if (state.errorMessage != null && state.errorMessage!.isNotEmpty) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(state.errorMessage!)));
}
if (state.isSuccess) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('绑定成功')));
Navigator.of(context).pop();
}
},
child: Scaffold(
backgroundColor: const Color(0xFFF3F8FD),
body: SafeArea(
child: BlocBuilder<BindDeviceCubit, BindDeviceState>(
builder: (context, state) {
if (state.isLoading) {
return const Center(
child: CircularProgressIndicator(color: _blue),
);
}
return Column(
children: [
_buildTopBar(),
_buildSteps(),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: _buildFormCard(state),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 12),
child: _buildSubmitButton(state),
),
],
);
},
),
),
),
),
);
}
// ===== 顶栏:返回 + 标题 =====
Widget _buildTopBar() {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
child: Row(
children: [
GestureDetector(
onTap: () => Navigator.of(context).pop(),
behavior: HitTestBehavior.opaque,
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.06),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: const Icon(Icons.arrow_back_ios, color: _blue, size: 18),
),
),
const SizedBox(width: 12),
const Text(
'绑定激活',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: _navy,
),
),
],
),
);
}
// ===== 步骤条:1/2 已完成 / 3 当前 =====
Widget _buildSteps() {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 28),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_stepNode(index: 1, label: '识别设备', mode: 'done'),
_stepLine(),
_stepNode(index: 2, label: '确认信息', mode: 'done'),
_stepLine(),
_stepNode(index: 3, label: '绑定激活', mode: 'active'),
],
),
);
}
Widget _stepNode({
required int index,
required String label,
required String mode,
}) {
final done = mode == 'done';
final active = mode == 'active';
final circle = Container(
width: 28,
height: 28,
decoration: BoxDecoration(
color: done
? _green
: active
? _blue
: const Color(0xFFE5E6EB),
shape: BoxShape.circle,
),
child: Center(
child: done
? const Icon(Icons.check, color: Colors.white, size: 16)
: Text(
'$index',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: active ? Colors.white : _gray,
),
),
),
);
return Column(
children: [
SizedBox(
width: 38,
height: 38,
child: Center(
child: active
? Container(
width: 38,
height: 38,
decoration: const BoxDecoration(
color: Color(0xFFD9EAFB),
shape: BoxShape.circle,
),
child: Center(child: circle),
)
: circle,
),
),
const SizedBox(height: 6),
Text(
label,
style: TextStyle(
fontSize: 11,
color: active ? _blue : _gray,
fontWeight: active ? FontWeight.w600 : FontWeight.w400,
),
),
],
);
}
Widget _stepLine() {
return Expanded(
child: Container(
height: 2,
margin: const EdgeInsets.only(top: 18, left: 8, right: 8),
color: const Color(0xFFDCE9F8),
),
);
}
// ===== 表单卡:逻辑与旧页一致(级联下拉 + 角色必填) =====
Widget _buildFormCard(BindDeviceState state) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.06),
blurRadius: 16,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildRoleTag(state.roleKey),
const SizedBox(height: 16),
_buildLabel('已选装备 ID', required: false),
const SizedBox(height: 8),
_buildReadonlyField(widget.scanResult),
const SizedBox(height: 16),
_buildLabel('所属组织', required: true),
const SizedBox(height: 8),
_buildOrgDropdown(state),
const SizedBox(height: 16),
_buildLabel('所属场站', required: false),
const SizedBox(height: 8),
_buildSiteDropdown(state),
const SizedBox(height: 16),
_buildLabel('负责人', required: _cubit.roleKey == 'user'),
const SizedBox(height: 8),
_buildUserDropdown(state),
],
),
);
}
Widget _buildRoleTag(String roleKey) {
final roleLabel =
const {
'admin': '管理员',
'manager': '组织管理员',
'siteManager': '场站管理员',
'user': '普通用户',
}[roleKey] ??
'普通用户';
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: const Color(0xFFE7F3FE),
borderRadius: BorderRadius.circular(8),
),
child: Text(
'当前角色:$roleLabel($roleKey)',
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: _blue,
),
),
);
}
Widget _buildLabel(String label, {required bool required}) {
return RichText(
text: TextSpan(
children: [
if (required)
const TextSpan(
text: '* ',
style: TextStyle(
color: Color(0xFFE5484D),
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: label,
style: const TextStyle(
color: _navy,
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
Widget _buildReadonlyField(String text) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
decoration: BoxDecoration(
color: _fill,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Expanded(
child: Text(
text,
style: const TextStyle(fontSize: 14, color: _navy),
overflow: TextOverflow.ellipsis,
),
),
const Icon(Icons.lock, size: 16, color: _gray),
],
),
);
}
int? _validValue(List<dynamic> list, int? selectedId) {
if (selectedId == null) return null;
final count = list.where((e) => e.id == selectedId).length;
return count == 1 ? selectedId : null;
}
Widget _buildOrgDropdown(BindDeviceState state) {
final enabled = _cubit.isOrgEnabled;
final selectedName = state.selectedOrgId != null
? state.orgList
.where((org) => org.id == state.selectedOrgId)
.fold<String?>(null, (_, org) => org.name)
: null;
if (!enabled) {
return _buildReadonlyField(selectedName ?? '未分配组织');
}
final validValue = _validValue(state.orgList, state.selectedOrgId);
return DropdownButtonFormField<int>(
value: validValue,
decoration: _dropdownDecoration('请选择'),
icon: const Icon(Icons.expand_more, color: _gray),
items: state.orgList.map((org) {
return DropdownMenuItem<int>(
value: org.id,
child: Text(
org.name,
style: const TextStyle(fontSize: 14, color: _navy),
overflow: TextOverflow.ellipsis,
),
);
}).toList(),
onChanged: (v) {
if (v != null) _cubit.onOrgChanged(v);
},
);
}
Widget _buildSiteDropdown(BindDeviceState state) {
final enabled = _cubit.isSiteEnabled && state.selectedOrgId != null;
final selectedName = state.selectedSiteId != null
? state.siteList
.where((site) => site.id == state.selectedSiteId)
.fold<String?>(null, (_, site) => site.name)
: null;
if (!enabled) {
return _buildReadonlyField(selectedName ?? '未分配场站');
}
final hintText = state.selectedOrgId == null ? '请先选择组织' : '请选择';
final validValue = _validValue(state.siteList, state.selectedSiteId);
return DropdownButtonFormField<int>(
value: validValue,
decoration: _dropdownDecoration(hintText),
icon: const Icon(Icons.expand_more, color: _gray),
items: state.siteList.map((site) {
return DropdownMenuItem<int>(
value: site.id,
child: Text(
site.name,
style: const TextStyle(fontSize: 14, color: _navy),
overflow: TextOverflow.ellipsis,
),
);
}).toList(),
onChanged: (v) {
if (v != null) _cubit.onSiteChanged(v);
},
);
}
Widget _buildUserDropdown(BindDeviceState state) {
final enabled = _cubit.isUserEnabled && state.selectedSiteId != null;
final selectedName = state.selectedUserId != null
? state.userList
.where((user) => user.id == state.selectedUserId)
.fold<String?>(null, (_, user) => user.name)
: null;
if (!enabled) {
return _buildReadonlyField(selectedName ?? '未分配负责人');
}
final hintText = state.selectedSiteId == null ? '请先选择场站' : '请选择';
final validValue = _validValue(state.userList, state.selectedUserId);
return DropdownButtonFormField<int>(
value: validValue,
decoration: _dropdownDecoration(hintText),
icon: const Icon(Icons.expand_more, color: _gray),
items: state.userList.map((user) {
return DropdownMenuItem<int>(
value: user.id,
child: Text(
user.name,
style: const TextStyle(fontSize: 14, color: _navy),
overflow: TextOverflow.ellipsis,
),
);
}).toList(),
onChanged: (v) {
if (v != null) _cubit.onUserChanged(v);
},
);
}
// 下拉框样式对齐登录页 V2 输入框:白底 + 外轮廓描边,聚焦变蓝
InputDecoration _dropdownDecoration(String hintText) {
return InputDecoration(
isDense: true,
filled: true,
fillColor: Colors.white,
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
hintText: hintText,
hintStyle: const TextStyle(color: _gray, fontSize: 14),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: _border),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: _blue, width: 1.2),
),
);
}
// ===== 底部按钮:逻辑与旧页「确定」一致,提交绑定 =====
Widget _buildSubmitButton(BindDeviceState state) {
final submitting = state.isSubmitting;
return Container(
height: 52,
decoration: BoxDecoration(
gradient: _btnGradient,
borderRadius: BorderRadius.circular(14),
boxShadow: [
BoxShadow(
color: _blue.withValues(alpha: 0.3),
blurRadius: 12,
offset: const Offset(0, 6),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: submitting ? null : _handleSubmit,
borderRadius: BorderRadius.circular(14),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: submitting
? [
const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
),
]
: const [
Icon(Icons.check, color: Colors.white, size: 20),
SizedBox(width: 10),
Text(
'确认绑定',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
],
),
),
),
);
}
void _handleSubmit() {
_cubit.submitBind(widget.scanResult);
}
}

View File

@@ -0,0 +1,425 @@
import 'package:flutter/material.dart';
import 'bind_activate_page_v2.dart';
/// 绑定设备页 V2:流程第二环节「确认设备信息」(02 设计稿新 UI)。
///
/// 只换 UI,点击逻辑和前提逻辑都不改:
/// - 扫描结果(scanResult,即扫出来的名字)在设备名称与设备序列号位置全量显示;
/// 其余信息扫描结果不提供,统一显示「未知」;
/// - 「选择设备归属」区块按需求暂不展示(不开发);
/// - 底部按钮只负责跳转第三环节「绑定激活」(BindActivatePageV2),
/// 绑定提交逻辑在第三步页(复制自旧 BindDevicePage,逻辑不变)。
class BindDevicePageV2 extends StatefulWidget {
final String scanResult;
const BindDevicePageV2({super.key, required this.scanResult});
@override
State<BindDevicePageV2> createState() => _BindDevicePageV2State();
}
class _BindDevicePageV2State extends State<BindDevicePageV2> {
static const _navy = Color(0xFF1A2B4A);
static const _gray = Color(0xFF86909C);
static const _blue = Color(0xFF1C96F6);
static const _green = Color(0xFF2FBF6B);
static const _greenDark = Color(0xFF1D9E57);
static const _greenBg = Color(0xFFE5F8EC);
static const _divider = Color(0xFFF0F4FA);
static const _unknown = '未知';
static const _btnGradient = LinearGradient(
colors: [Color(0xFF2BAFFE), Color(0xFF1C96F6), Color(0xFF0B7DEE)],
);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF3F8FD),
body: SafeArea(
child: Column(
children: [
_buildTopBar(),
_buildSteps(),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildBanner(),
const SizedBox(height: 12),
_buildDeviceCard(),
const SizedBox(height: 12),
_buildVerifyNotice(),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 12),
child: _buildNextButton(),
),
],
),
),
);
}
// ===== 顶栏:返回 + 标题 =====
Widget _buildTopBar() {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
child: Row(
children: [
GestureDetector(
onTap: () => Navigator.of(context).pop(),
behavior: HitTestBehavior.opaque,
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.06),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: const Icon(Icons.arrow_back_ios, color: _blue, size: 18),
),
),
const SizedBox(width: 12),
const Text(
'确认设备信息',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: _navy,
),
),
],
),
);
}
// ===== 步骤条:1 已完成 / 2 当前 / 3 待进行 =====
Widget _buildSteps() {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 28),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_stepNode(index: 1, label: '识别设备', mode: 'done'),
_stepLine(),
_stepNode(index: 2, label: '确认信息', mode: 'active'),
_stepLine(),
_stepNode(index: 3, label: '绑定激活', mode: 'wait'),
],
),
);
}
Widget _stepNode({
required int index,
required String label,
required String mode,
}) {
final done = mode == 'done';
final active = mode == 'active';
final circle = Container(
width: 28,
height: 28,
decoration: BoxDecoration(
color: done
? _green
: active
? _blue
: const Color(0xFFE5E6EB),
shape: BoxShape.circle,
),
child: Center(
child: done
? const Icon(Icons.check, color: Colors.white, size: 16)
: Text(
'$index',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: active ? Colors.white : _gray,
),
),
),
);
return Column(
children: [
SizedBox(
width: 38,
height: 38,
child: Center(
child: active
? Container(
width: 38,
height: 38,
decoration: const BoxDecoration(
color: Color(0xFFD9EAFB),
shape: BoxShape.circle,
),
child: Center(child: circle),
)
: circle,
),
),
const SizedBox(height: 6),
Text(
label,
style: TextStyle(
fontSize: 11,
color: active ? _blue : _gray,
fontWeight: active ? FontWeight.w600 : FontWeight.w400,
),
),
],
);
}
Widget _stepLine() {
return Expanded(
child: Container(
height: 2,
margin: const EdgeInsets.only(top: 18, left: 8, right: 8),
color: const Color(0xFFDCE9F8),
),
);
}
// ===== 识别成功提示条 =====
Widget _buildBanner() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 11),
decoration: BoxDecoration(
color: _greenBg,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
const Icon(Icons.check_circle_outline, color: _green, size: 20),
const SizedBox(width: 8),
Expanded(
child: Text(
'已识别设备,请确认信息与归属',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: _greenDark,
),
),
),
],
),
);
}
// ===== 设备信息卡:扫出来的名字填名称/序列号,其余未知 =====
Widget _buildDeviceCard() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.06),
blurRadius: 16,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(12),
// 设备图复用登录页 V2 的机器人图
child: Container(
height: 180,
width: double.infinity,
color: const Color(0xFFEAF3FC),
child: Center(
child: Image.asset(
'assets/images/robot_logo_login.png',
height: 150,
fit: BoxFit.contain,
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 14),
child: Row(
children: [
Expanded(
child: Text(
widget.scanResult,
// 字号收小并允许换行:扫出来的名字必须全显示,不截断
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: _navy,
height: 1.3,
),
),
),
const SizedBox(width: 10),
_buildBadge(_unknown),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
_unknown,
style: const TextStyle(fontSize: 13, color: _gray),
),
),
const Divider(height: 28, thickness: 1, color: _divider),
_infoRow('设备序列号', widget.scanResult),
_infoRow('设备绑定状态', _unknown),
_infoRow('设备连接', _unknown),
_infoRow('服务区域', _unknown),
],
),
);
}
Widget _buildBadge(String text) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: const Color(0xFFF0F2F5),
borderRadius: BorderRadius.circular(8),
),
child: Text(
text,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Color(0xFF6B7280),
),
),
);
}
Widget _infoRow(String label, String value) {
final isUnknown = value == _unknown;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 9),
child: Row(
children: [
Text(label, style: const TextStyle(fontSize: 14, color: _gray)),
const SizedBox(width: 12),
// 值统一占满剩余宽度并右对齐,保证每行右边缘齐平不乱
Expanded(
child: Text(
value,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: isUnknown ? _gray : _navy,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.right,
),
),
],
),
);
}
// ===== 归属验证说明(静态提示,无交互) =====
Widget _buildVerifyNotice() {
return Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: const Color(0xFFEAF4FE),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xFFD6E9FC)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.verified_user_outlined, color: _blue, size: 20),
const SizedBox(width: 8),
Text(
'设备归属验证',
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
color: _blue,
),
),
],
),
const SizedBox(height: 6),
Padding(
padding: const EdgeInsets.only(left: 28),
child: Text(
'仅扫描 SN 不代表已获得控制权。绑定前需要激活凭证或设备本地确认。',
style: TextStyle(fontSize: 13, color: _gray, height: 1.6),
),
),
],
),
);
}
// ===== 底部按钮:只负责跳转第三环节「绑定激活」,不在这里提交绑定 =====
Widget _buildNextButton() {
return Container(
height: 52,
decoration: BoxDecoration(
gradient: _btnGradient,
borderRadius: BorderRadius.circular(14),
boxShadow: [
BoxShadow(
color: _blue.withValues(alpha: 0.3),
blurRadius: 12,
offset: const Offset(0, 6),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => BindActivatePageV2(scanResult: widget.scanResult),
),
),
borderRadius: BorderRadius.circular(14),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.arrow_forward, color: Colors.white, size: 20),
SizedBox(width: 10),
Text(
'验证归属并继续',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
],
),
),
),
);
}
}

View File

@@ -14,7 +14,7 @@ import 'package:get_it/get_it.dart';
import '../../../../../core/services/device_permission_service.dart';
import '../../domain/entities/device_entity.dart';
import '../../domain/usecases/get_device_by_spilt_code_usecase.dart';
import 'bind_device_page.dart';
import 'bind_device_page_v2.dart';
class BleDeviceDetailPage extends StatefulWidget {
final BluetoothDevice device;
@@ -345,7 +345,7 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => BindDevicePage(scanResult: matchedDevice.name),
builder: (_) => BindDevicePageV2(scanResult: matchedDevice.name),
),
);
} catch (e) {

View File

@@ -0,0 +1,827 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
import 'package:maibu_satabot_v2/features/pv_control/presentation/widgets/pv_work_map.dart';
import '../../../../devices/domain/entities/device_entity.dart';
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
import '../../../local_camera/presentation/pages/local_camera_page.dart';
import '../../data/models/robot_data_model.dart';
import '../widgets/device_card_v2.dart';
import 'robot_control_page.dart';
/// 设备详情页 V2:点设备「直接进入」分支的新页面(STD 概览设计稿)。
///
/// 入口约定(前置判定一行未动):
/// - 列表点击 hasHost=false → 仍走蓝牙连接流程(旧逻辑);
/// - 列表点击 hasHost=true → 直接进入本页;
/// - 本页顶栏铃铛 / 「远程遥控」磁贴 → 跳回旧页 RobotControlPage,
/// 跳转前置(setTargetDevice + robotMap)与旧直进分支逐行一致,方便新旧对照。
///
/// 数据口径:在线态/电量/任务用接口真值(与列表卡同一口径,不造假);
/// 后端暂未返回的字段(GNSS/割刀/故障等)显示 --,版本/位置用 DeviceV2Display 稳定占位。
class DeviceDetailPageV2 extends StatefulWidget {
final RobotDataModel robot;
const DeviceDetailPageV2({super.key, required this.robot});
@override
State<DeviceDetailPageV2> createState() => _DeviceDetailPageV2State();
}
class _DeviceDetailPageV2State extends State<DeviceDetailPageV2> {
static const _navy = Color(0xFF1A2B4A);
static const _gray = Color(0xFF86909C);
static const _blue = Color(0xFF1C96F6);
static const _track = Color(0xFFE4EEFB);
static const _statBg = Color(0xFFF6FAFE);
static const _onlineGreen = Color(0xFF2FBF6B);
static const _onlineBg = Color(0xFFE5F8EC);
static const _offlineGray = Color(0xFF6B7280);
static const _offlineBg = Color(0xFFF0F2F5);
static const _tabs = ['概览', '监测', '控制', '记录', '设置'];
int _tab = 0;
/// 在线态映射与列表页 _robotV2Status 同口径:离线 / 作业中 / 在线
DeviceV2Status get _status {
if (!widget.robot.isOnline) return DeviceV2Status.offline;
final t = widget.robot.task.trim();
if (t.isEmpty || t == '待机中' || t == '充电中') {
return DeviceV2Status.online;
}
return DeviceV2Status.working;
}
String get _displayName {
final alias = widget.robot.alias;
return (alias != null && alias.isNotEmpty) ? alias : widget.robot.name;
}
String get _workLabel => switch (_status) {
DeviceV2Status.working => '作业中',
DeviceV2Status.online => '待机',
DeviceV2Status.offline => '离线',
};
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF3F8FD),
body: SafeArea(
child: Column(
children: [
_buildTopBar(),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildHeaderCard(),
const SizedBox(height: 12),
_buildTabs(),
const SizedBox(height: 14),
if (_tab == 0) ...[
_buildOverviewSection(),
const SizedBox(height: 18),
_buildMapSection(),
const SizedBox(height: 18),
_buildFunctionSection(),
const SizedBox(height: 14),
_buildAllFunctionButton(),
] else
_buildPlaceholder(),
const SizedBox(height: 12),
const Text(
'示例数据;常用功能只是导航入口,不会重复创建功能页面',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 11, color: Color(0xFFB9C2CF)),
),
],
),
),
),
],
),
),
);
}
// ===== 顶栏:返回 + 标题 + 铃铛(铃铛=回旧页对照) =====
Widget _buildTopBar() {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
child: Row(
children: [
GestureDetector(
onTap: () => Navigator.of(context).pop(),
behavior: HitTestBehavior.opaque,
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.06),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: const Icon(Icons.arrow_back_ios, color: _blue, size: 18),
),
),
const SizedBox(width: 12),
const Text(
'设备详情',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: _navy,
),
),
const Spacer(),
GestureDetector(
onTap: _openLegacyPage,
behavior: HitTestBehavior.opaque,
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.06),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: const Icon(
Icons.notifications_none,
color: _blue,
size: 20,
),
),
),
],
),
);
}
// ===== 设备头卡:图 + 名称/型号版本/SN + 状态药丸 =====
Widget _buildHeaderCard() {
final offline = _status == DeviceV2Status.offline;
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.06),
blurRadius: 16,
offset: const Offset(0, 4),
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildThumb(offline),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Flexible(
child: Text(
_displayName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 19,
fontWeight: FontWeight.w800,
color: _navy,
),
),
),
// 编辑(改名):后端能力未接,统一提示
GestureDetector(
onTap: () =>
CapsuleToast.show('功能暂未开发', showCheck: false),
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 6),
child: Icon(
Icons.edit_outlined,
size: 16,
color: _blue,
),
),
),
],
),
const SizedBox(height: 6),
Text(
'${widget.robot.type} · ${DeviceV2Display.editionOf(widget.robot.name)}',
style: const TextStyle(fontSize: 13, color: _gray),
),
const SizedBox(height: 6),
Text(
'SN: ${DeviceV2Display.maskedSn(widget.robot.name)}',
style: const TextStyle(fontSize: 13, color: _gray),
),
const SizedBox(height: 8),
Row(
children: [
_buildStatusPill(),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 4,
),
decoration: BoxDecoration(
color: _offlineBg,
borderRadius: BorderRadius.circular(20),
),
child: Text(
_workLabel,
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: _offlineGray,
),
),
),
],
),
],
),
),
],
),
);
}
/// 缩略图:与列表卡同款(透明底车图,离线置灰)
Widget _buildThumb(bool offline) {
return Container(
width: 110,
height: 92,
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,
);
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 _buildStatusPill() {
final offline = _status == DeviceV2Status.offline;
final color = offline ? _offlineGray : _onlineGreen;
final bg = offline ? _offlineBg : _onlineBg;
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
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(
offline ? '离线' : '在线',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: color,
),
),
],
),
);
}
// ===== 页签:概览/监测/控制/记录/设置 =====
Widget _buildTabs() {
return Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: _track,
borderRadius: BorderRadius.circular(14),
),
child: Row(
children: [
for (int i = 0; i < _tabs.length; i++) ...[
if (i > 0) const SizedBox(width: 2),
Expanded(child: _tabSegment(i)),
],
],
),
);
}
Widget _tabSegment(int i) {
final selected = _tab == i;
return GestureDetector(
onTap: () => setState(() => _tab = i),
behavior: HitTestBehavior.opaque,
child: Container(
height: 38,
decoration: BoxDecoration(
color: selected ? Colors.white : Colors.transparent,
borderRadius: BorderRadius.circular(11),
boxShadow: selected
? [
BoxShadow(
color: _blue.withValues(alpha: 0.10),
blurRadius: 6,
offset: const Offset(0, 2),
),
]
: null,
),
alignment: Alignment.center,
child: Text(
_tabs[i],
style: TextStyle(
fontSize: 14,
fontWeight: selected ? FontWeight.w700 : FontWeight.w400,
color: selected ? _blue : _gray,
),
),
),
);
}
// ===== 概览:运行概况六宫格 =====
Widget _buildOverviewSection() {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
const Text(
'机器人运行概况',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w800,
color: _navy,
),
),
const Spacer(),
const Text(
'状态更新:--',
style: TextStyle(fontSize: 12, color: _gray),
),
],
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: _statCard(
Icons.battery_std_outlined,
_status == DeviceV2Status.offline
? '--'
: '${widget.robot.battery.round()}%',
'能源',
),
),
const SizedBox(width: 10),
Expanded(child: _statCard(Icons.monitor_heart_outlined, _workLabel, '设备状态')),
const SizedBox(width: 10),
Expanded(child: _statCard(Icons.location_on_outlined, '--', 'GNSS定位')),
],
),
const SizedBox(height: 10),
Row(
children: [
Expanded(
child: _statCard(
Icons.wifi_outlined,
widget.robot.isOnline ? '正常' : '离线',
'云端通信',
),
),
const SizedBox(width: 10),
Expanded(child: _statCard(Icons.content_cut_outlined, '--', '割刀状态')),
const SizedBox(width: 10),
Expanded(child: _statCard(Icons.verified_user_outlined, '--', '当前故障')),
],
),
],
);
}
Widget _statCard(IconData icon, String value, String label) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 6),
decoration: BoxDecoration(
color: _statBg,
borderRadius: BorderRadius.circular(14),
),
child: Column(
children: [
Icon(icon, size: 22, color: _navy),
const SizedBox(height: 8),
Text(
value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 19,
fontWeight: FontWeight.w800,
color: _navy,
),
),
const SizedBox(height: 4),
Text(
label,
style: const TextStyle(fontSize: 11, color: _gray),
),
],
),
);
}
// ===== 位置与当前任务:地图卡 =====
Widget _buildMapSection() {
final location = DeviceV2Display.locationOf(widget.robot.name);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
const Text(
'位置与当前任务',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w800,
color: _navy,
),
),
const Spacer(),
GestureDetector(
onTap: () => CapsuleToast.show('功能暂未开发', showCheck: false),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'查看地图',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: _blue,
),
),
Icon(Icons.arrow_forward, size: 14, color: _blue),
],
),
),
],
),
const SizedBox(height: 12),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.06),
blurRadius: 16,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(12),
child: SizedBox(
height: 150,
width: double.infinity,
child: Stack(
children: [
// 复用作业地图组件(只读,禁手势避免与滚动冲突)
const Positioned.fill(
child: PvWorkMap(interactive: false),
),
Positioned(
left: 10,
top: 10,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 6,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.08),
blurRadius: 6,
offset: const Offset(0, 2),
),
],
),
child: Text(
location,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: _navy,
),
),
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.only(top: 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'当前位置:$location',
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
color: _navy,
),
),
const SizedBox(height: 4),
const Text(
'仅显示当前位置 · 任务以控制页为准',
style: TextStyle(fontSize: 12, color: _gray),
),
],
),
),
const Text(
'--',
style: TextStyle(fontSize: 12, color: _gray),
),
],
),
),
],
),
),
],
);
}
// ===== 常用功能:六磁贴(导航入口,不重建功能页) =====
Widget _buildFunctionSection() {
final tiles = <(IconData, String, VoidCallback)>[
(
Icons.videocam_outlined,
'实时图传',
() => Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const LocalCameraPage()),
),
),
(Icons.sports_esports_outlined, '远程遥控', _openLegacyPage),
(
Icons.my_location_outlined,
'一键寻车',
() => CapsuleToast.show('功能暂未开发', showCheck: false),
),
(
Icons.power_settings_new,
'APP开关机',
() => CapsuleToast.show('功能暂未开发', showCheck: false),
),
(
Icons.warning_amber_outlined,
'故障诊断',
() => CapsuleToast.show('功能暂未开发', showCheck: false),
),
(
Icons.sensors_outlined,
'传感器监测',
() => CapsuleToast.show('功能暂未开发', showCheck: false),
),
];
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
const Text(
'常用功能',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w800,
color: _navy,
),
),
const Spacer(),
GestureDetector(
onTap: () => CapsuleToast.show('功能暂未开发', showCheck: false),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.edit_outlined, size: 14, color: _blue),
SizedBox(width: 4),
Text(
'编辑排序',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: _blue,
),
),
],
),
),
],
),
const SizedBox(height: 12),
Row(
children: [
Expanded(child: _tile(tiles[0])),
const SizedBox(width: 10),
Expanded(child: _tile(tiles[1])),
const SizedBox(width: 10),
Expanded(child: _tile(tiles[2])),
],
),
const SizedBox(height: 10),
Row(
children: [
Expanded(child: _tile(tiles[3])),
const SizedBox(width: 10),
Expanded(child: _tile(tiles[4])),
const SizedBox(width: 10),
Expanded(child: _tile(tiles[5])),
],
),
],
);
}
Widget _tile((IconData, String, VoidCallback) t) {
final (icon, label, onTap) = t;
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 6),
decoration: BoxDecoration(
color: _statBg,
borderRadius: BorderRadius.circular(14),
),
child: Column(
children: [
Icon(icon, size: 26, color: _blue),
const SizedBox(height: 8),
Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: _navy,
),
),
],
),
),
);
}
Widget _buildAllFunctionButton() {
return GestureDetector(
onTap: () => CapsuleToast.show('功能暂未开发', showCheck: false),
child: Container(
height: 48,
decoration: BoxDecoration(
color: const Color(0xFFEAF4FE),
borderRadius: BorderRadius.circular(14),
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'查看全部功能',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
color: _blue,
),
),
SizedBox(width: 10),
Icon(Icons.arrow_forward, size: 18, color: _blue),
],
),
),
);
}
// ===== 非概览页签:占位 =====
Widget _buildPlaceholder() {
return Container(
height: 320,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.construction_outlined,
size: 42,
color: Color(0xFFC9CDD4),
),
const SizedBox(height: 10),
Text(
'${_tabs[_tab]}模块暂未开发',
style: const TextStyle(fontSize: 14, color: _gray),
),
const SizedBox(height: 4),
const Text(
'点右上角铃铛可对照旧版页面',
style: TextStyle(fontSize: 12, color: Color(0xFFB9C2CF)),
),
],
),
),
);
}
// ===== 铃铛/远程遥控:回旧控制详情页,前置与旧直进分支逐行一致 =====
void _openLegacyPage() {
final robot = widget.robot;
final device = DeviceEntity(
deviceName: robot.name,
productId: -1,
productName: robot.type,
tenantId: 0,
tenantName: '',
status: robot.isOnline ? 1 : 0,
onlineStatus: robot.isOnline ? 1 : 0,
);
final remoteCubit = GetIt.I<RemoteControlCubit>();
remoteCubit.setTargetDevice(device);
final robotMap = <String, dynamic>{
'name': robot.name,
'id': robot.id,
'alias': robot.alias,
'type': robot.type,
'status': robot.status,
'battery': robot.battery,
'task': robot.task,
};
Navigator.push(
context,
MaterialPageRoute(builder: (_) => RobotControlPage(robot: robotMap)),
);
}
}

View File

@@ -31,13 +31,15 @@ import '../widgets/bluetooth_scan_modal.dart';
import '../../domain/entities/drone_station_entity.dart'; // 🔥 添加 DroneStationEntity 导入
import 'robot_list_page.dart';
import 'robot_control_page.dart';
import 'device_detail_page_v2.dart';
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 'qr_scanner_page_v2.dart';
import 'bind_device_page_v2.dart';
import 'no_device_page_v2.dart';
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
import '../widgets/device_card_v2.dart';
import 'package:maibu_satabot_v2/features/pv_control/presentation/widgets/pv_work_map.dart';
import '../../data/models/robot_data_model.dart';
import '../../../local_camera/presentation/pages/local_camera_page.dart';
import '../../../usb_camera/presentation/pages/usb_camera_page.dart';
@@ -281,6 +283,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
/// 状态过滤药丸:all / online / working / offline
String _statusFilter = 'all';
/// 视图模式:card = 卡片视图(02 设计稿);overview = 集中概览(03 设计稿)
String _viewMode = 'card';
static const _v2Navy = Color(0xFF1A2B4A);
static const _v2Gray = Color(0xFF86909C);
static const _v2Blue = Color(0xFF1C96F6);
@@ -449,6 +454,18 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
_ => items,
};
// 集中概览模式:统计卡 + 设备分布地图 + 复用状态药丸 + 设备表格
if (_viewMode == 'overview') {
return _buildV2Overview(
context,
items.length,
visible,
onlineCount,
workingCount,
offlineCount,
);
}
final stillLoading =
items.isEmpty &&
(robotState is RobotListLoading || stationState is DroneStationLoading);
@@ -590,7 +607,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
return;
}
// hasHost == true → 走原来的逻辑
// hasHost == true → 走原来的逻辑:前置(setTargetDevice)不变,
// 跳转目标换成新设备详情页(V2 概览设计稿);
// 页内铃铛/远程遥控再回旧 RobotControlPage,方便新旧对照。
debugPrint('✅ [V2] hasHost=true,走正常控制流程');
final device = DeviceEntity(
@@ -606,20 +625,10 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
final remoteCubit = GetIt.I<RemoteControlCubit>();
remoteCubit.setTargetDevice(device);
final robotMap = {
'name': robot.name,
'id': robot.id,
'alias': robot.alias,
'type': robot.type,
'status': robot.status,
'battery': robot.battery,
'task': robot.task,
};
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RobotControlPage(robot: robotMap),
builder: (context) => DeviceDetailPageV2(robot: robot),
),
);
return;
@@ -850,72 +859,79 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
);
}
// ===== 卡片视图 / 集中概览 切换(集中概览二级未开发) =====
// ===== 卡片视图 / 集中概览 切换(03 设计稿:浅蓝轨道 + 白色选中胶囊) =====
Widget _buildViewToggle() {
final isCard = _viewMode == 'card';
return Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
child: Container(
height: 44,
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.6),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: _v2Border),
color: const Color(0xFFDCE9F8),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
// 选中项:蓝渐变填充 + 白字,与全局主色按钮一致
Expanded(
child: Container(
height: double.infinity,
decoration: BoxDecoration(
gradient: _v2BtnGradient,
borderRadius: BorderRadius.circular(11),
boxShadow: [
BoxShadow(
color: _v2Blue.withValues(alpha: 0.3),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.grid_view_rounded,
size: 16,
color: Colors.white,
),
SizedBox(width: 6),
Text(
'卡片视图',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
],
),
child: _buildToggleSegment(
'卡片视图',
Icons.grid_view_rounded,
isCard,
() => setState(() => _viewMode = 'card'),
),
),
// 未选中项:透明底 + 灰字
Expanded(
child: GestureDetector(
onTap: _v2Todo,
behavior: HitTestBehavior.opaque,
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.bar_chart_rounded, size: 16, color: _v2Gray),
SizedBox(width: 6),
Text(
'集中概览',
style: TextStyle(fontSize: 13, color: _v2Gray),
),
],
),
child: _buildToggleSegment(
'集中概览',
Icons.bar_chart_rounded,
!isCard,
() => setState(() => _viewMode = 'overview'),
),
),
],
),
),
);
}
Widget _buildToggleSegment(
String label,
IconData icon,
bool selected,
VoidCallback onTap,
) {
return GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: Container(
// 撑满轨道内高:否则胶囊会被内容挤矮,选中态变形不好看
height: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 10),
decoration: selected
? BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(9),
boxShadow: [
BoxShadow(
color: _v2Blue.withValues(alpha: 0.15),
blurRadius: 6,
offset: const Offset(0, 2),
),
],
)
: null,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: 16, color: selected ? _v2Blue : _v2Gray),
const SizedBox(width: 6),
Text(
label,
style: TextStyle(
fontSize: 13,
fontWeight: selected ? FontWeight.w600 : FontWeight.w400,
color: selected ? _v2Blue : _v2Gray,
),
),
],
@@ -1005,7 +1021,445 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
);
}
// ===== 添加机器人底部弹窗:与无设备页同一套,各项保持原跳转 =====
// ===== 集中概览(03 设计稿):统计卡 + 分布地图 + 复用药丸 + 设备表格 =====
Widget _buildV2Overview(
BuildContext context,
int all,
List<_V2DeviceItem> visible,
int onlineCount,
int workingCount,
int offlineCount,
) {
return Scaffold(
backgroundColor: const Color(0xFFFAFCFF),
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: Column(
children: [
_buildOverviewAppBar(),
_buildOverviewHeader(),
_buildViewToggle(),
Expanded(
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.fromLTRB(0, 0, 0, 24),
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
child: _buildStatCards(
all,
onlineCount,
workingCount,
offlineCount,
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: _buildDistributionCard(context, all),
),
// 状态标签栏:直接复用卡片视图同一套药丸组件
_buildStatusPills(all, onlineCount, workingCount, offlineCount),
Padding(
padding: const EdgeInsets.fromLTRB(16, 10, 16, 0),
child: _buildOverviewTable(visible),
),
],
),
),
],
),
),
],
),
);
}
/// 概览顶栏:返回箭头回到卡片视图 + 标题
Widget _buildOverviewAppBar() {
return SizedBox(
height: 44,
child: Row(
children: [
const SizedBox(width: 6),
IconButton(
onPressed: () => setState(() => _viewMode = 'card'),
icon: const Icon(Icons.chevron_left, color: _v2Navy, size: 26),
),
Expanded(
child: Text(
'设备集中概览',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: _v2Navy,
),
),
),
const SizedBox(width: 48),
],
),
);
}
Widget _buildOverviewHeader() {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 0),
child: SizedBox(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
'设备集中概览',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: _v2Navy,
),
),
SizedBox(height: 6),
Text(
'适合企业多机器人集中管理',
style: TextStyle(fontSize: 13, color: _v2Gray),
),
],
),
),
);
}
/// 四张统计卡:设备总数 / 在线设备 / 作业中 / 告警离线
Widget _buildStatCards(int all, int online, int working, int offline) {
final stats = [
(Icons.smart_toy_rounded, _v2Blue, all, '设备总数'),
(Icons.wifi_rounded, _v2Blue, online, '在线设备'),
(Icons.play_circle_fill_rounded, const Color(0xFF2FBF6B), working, '作业中'),
(Icons.warning_amber_rounded, const Color(0xFFE5484D), offline, '告警/离线'),
];
return Row(
children: [
for (var i = 0; i < stats.length; i++) ...[
if (i > 0) const SizedBox(width: 8),
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 4),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: _v2Border),
),
child: Column(
children: [
Icon(stats[i].$1, size: 20, color: stats[i].$2),
const SizedBox(height: 6),
Text(
'${stats[i].$3}',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: _v2Navy,
),
),
const SizedBox(height: 2),
Text(
stats[i].$4,
style: const TextStyle(fontSize: 11, color: _v2Gray),
),
],
),
),
),
],
],
);
}
/// 设备分布卡:复用路径规划同源实时地图 PvWorkMap(interactive=false
/// 防与外层 ListView 手势冲突,PV 小卡同款用法)
Widget _buildDistributionCard(BuildContext context, int all) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: _v2Border),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(14, 12, 14, 10),
child: Row(
children: [
const Text(
'设备分布',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: _v2Navy,
),
),
const Spacer(),
GestureDetector(
onTap: () => setState(() => _viewMode = 'card'),
behavior: HitTestBehavior.opaque,
child: Row(
children: [
Text(
'共 $all 台设备',
style: const TextStyle(
fontSize: 12,
color: _v2Blue,
),
),
const Icon(
Icons.chevron_right,
size: 16,
color: _v2Blue,
),
],
),
),
],
),
),
ClipRRect(
borderRadius: const BorderRadius.vertical(
bottom: Radius.circular(15),
),
child: SizedBox(
height: 200,
child: PvWorkMap(interactive: false),
),
),
],
),
);
}
/// 设备列表表格:表头 + 行(点击复用卡片视图同一套 _v2ItemTap 逻辑)
Widget _buildOverviewTable(List<_V2DeviceItem> visible) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: _v2Border),
),
child: Column(
children: [
const Padding(
padding: EdgeInsets.fromLTRB(14, 12, 14, 8),
child: Row(
children: [
Expanded(
flex: 5,
child: Text(
'设备信息',
style: TextStyle(fontSize: 12, color: _v2Gray),
),
),
Expanded(
flex: 3,
child: Text(
'状态',
style: TextStyle(fontSize: 12, color: _v2Gray),
),
),
Expanded(
flex: 2,
child: Text(
'电量',
style: TextStyle(fontSize: 12, color: _v2Gray),
),
),
Expanded(
flex: 4,
child: Text(
'位置/当前任务',
style: TextStyle(fontSize: 12, color: _v2Gray),
),
),
SizedBox(width: 16),
],
),
),
if (visible.isEmpty)
const Padding(
padding: EdgeInsets.all(32),
child: Text(
'没有匹配的设备',
style: TextStyle(fontSize: 13, color: _v2Gray),
),
)
else
...visible.map((e) => _buildOverviewRow(e)),
const SizedBox(height: 8),
],
),
);
}
Widget _buildOverviewRow(_V2DeviceItem e) {
return GestureDetector(
onTap: () => _v2ItemTap(context, e),
behavior: HitTestBehavior.opaque,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 4),
decoration: const BoxDecoration(
border: Border(bottom: BorderSide(color: _v2Border)),
),
child: Row(
children: [
Expanded(
flex: 5,
child: Row(
children: [
_buildOverviewThumb(e),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
e.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: _v2Navy,
),
),
const SizedBox(height: 2),
Text(
'${DeviceV2Display.versionOf(e.snKey)} SN: ${DeviceV2Display.maskedSn(e.snKey)}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 10,
color: _v2Gray,
),
),
],
),
),
],
),
),
Expanded(flex: 3, child: _buildOverviewBadge(e.status)),
Expanded(
flex: 2,
child: Text(
_buildOverviewBattery(e),
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: _v2Navy,
),
),
),
Expanded(
flex: 4,
child: Text(
e.robot != null
? '${DeviceV2Display.locationOf(e.snKey)} · ${e.robot!.task}'
: DeviceV2Display.locationOf(e.snKey),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 11, color: _v2Gray),
),
),
const Icon(Icons.chevron_right, size: 18, color: Color(0xFFC9CDD4)),
],
),
),
);
}
Widget _buildOverviewBadge(DeviceV2Status status) {
final (label, fg, bg, icon) = switch (status) {
DeviceV2Status.working => (
'作业中',
const Color(0xFF2FBF6B),
const Color(0xFFE5F8EC),
Icons.play_arrow_rounded,
),
DeviceV2Status.online => (
'在线',
_v2Blue,
const Color(0xFFE7F3FE),
Icons.wifi_rounded,
),
DeviceV2Status.offline => (
'离线',
const Color(0xFF6B7280),
const Color(0xFFF0F2F5),
Icons.pause_rounded,
),
};
return Align(
alignment: Alignment.centerLeft,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: bg,
borderRadius: BorderRadius.circular(10),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 11, color: fg),
const SizedBox(width: 3),
Text(
label,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w600,
color: fg,
),
),
],
),
),
);
}
String _buildOverviewBattery(_V2DeviceItem e) {
final b = e.battery;
if (e.status == DeviceV2Status.offline || b == null) return '—';
return '$b%';
}
/// 行内设备缩略图:蓝渐变底 + logo;离线置灰
Widget _buildOverviewThumb(_V2DeviceItem e) {
final offline = e.status == DeviceV2Status.offline;
return Container(
width: 40,
height: 40,
decoration: BoxDecoration(
gradient: offline
? const LinearGradient(colors: [Color(0xFFB9C0CB), Color(0xFF9AA3AF)])
: _v2BtnGradient,
borderRadius: BorderRadius.circular(10),
),
padding: const EdgeInsets.all(7),
child: Image.asset('assets/images/shebei-logo.png'),
);
}
// ===== 添加机器人底部弹层:与无设备页同一套,各项保留原跳转 =====
void _showV2AddSheet(BuildContext context) {
showModalBottomSheet(
context: context,
@@ -1051,12 +1505,12 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
onTap: () async {
Navigator.pop(sheetCtx);
final result = await Navigator.of(context).push<String>(
MaterialPageRoute(builder: (_) => const QrScannerPage()),
MaterialPageRoute(builder: (_) => const QrScannerPageV2()),
);
if (result != null && context.mounted) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => BindDevicePage(scanResult: result),
builder: (_) => BindDevicePageV2(scanResult: result),
),
);
// 绑定后重拉:统计 + 机器人/机场列表一起刷新
@@ -1682,7 +2136,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
return;
}
// hasHost == true → 走原来的逻辑
// hasHost == true → 走原来的逻辑:前置(setTargetDevice)不变,
// 跳转目标换成新设备详情页(V2 概览设计稿);
// 页内铃铛/远程遥控再回旧 RobotControlPage,方便新旧对照。
debugPrint('✅ [全部-EmbeddedRobotList] hasHost=true,走正常控制流程');
// 1. 将当前机器人设置为全局待控制设备
@@ -1702,22 +2158,12 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
'✅ [全部-EmbeddedRobotList] setTargetDevice 已调用',
);
// 2. 跳转到机器人控制页面
final robotMap = {
'name': robot.name,
'id': robot.id,
'alias': robot.alias,
'type': robot.type,
'status': robot.status,
'battery': robot.battery,
'task': robot.task,
};
// 2. 跳转到新设备详情页
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
RobotControlPage(robot: robotMap),
DeviceDetailPageV2(robot: robot),
),
);
},
@@ -2015,14 +2461,14 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
Navigator.pop(ctx);
final result = await Navigator.of(context).push<String>(
MaterialPageRoute(
builder: (_) => const QrScannerPage(),
builder: (_) => const QrScannerPageV2(),
),
);
if (result != null && mounted) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) =>
BindDevicePage(scanResult: result),
BindDevicePageV2(scanResult: result),
),
);
}

View File

@@ -9,8 +9,8 @@ import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.
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';
import 'bind_device_page_v2.dart';
import 'qr_scanner_page_v2.dart';
/// 无设备首页 —— 按「01_无设备首页」设计稿实现。
///
@@ -439,12 +439,12 @@ class NoDevicePageV2 extends StatelessWidget {
onTap: () async {
Navigator.pop(sheetCtx);
final result = await Navigator.of(context).push<String>(
MaterialPageRoute(builder: (_) => const QrScannerPage()),
MaterialPageRoute(builder: (_) => const QrScannerPageV2()),
);
if (result != null && context.mounted) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => BindDevicePage(scanResult: result),
builder: (_) => BindDevicePageV2(scanResult: result),
),
);
// 绑定流程结束后重拉设备列表,有设备则自动退回正常列表页

View File

@@ -0,0 +1,599 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
/// 添加机器人扫码页 V2 —— 按「01_添加设备_支持跳过」设计稿换皮。
///
/// 由 qr_scanner_page.dart 复制而来:MobileScanner 识别到二维码后 pop 回传码值、
/// 闪光灯 toggleTorch 等逻辑与旧页一致;新增的手动输入 SN + 「识别设备」按钮
/// 走同一 pop 契约回传,调用方(BindDevicePage(scanResult:))无需改动。
/// 旧页保留可随时回退。
class QrScannerPageV2 extends StatefulWidget {
const QrScannerPageV2({super.key});
@override
State<QrScannerPageV2> createState() => _QrScannerPageV2State();
}
class _QrScannerPageV2State extends State<QrScannerPageV2>
with SingleTickerProviderStateMixin {
final MobileScannerController _controller = MobileScannerController();
final _snController = TextEditingController();
bool _isScanned = false;
/// 扫描线上下往复动画(纯视觉)
late final AnimationController _scanLineController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1800),
)..repeat(reverse: true);
static const _navy = Color(0xFF1A2B4A);
static const _gray = Color(0xFF86909C);
static const _blue = Color(0xFF1C96F6);
static const _border = Color(0xFFE9F1FA);
static const _btnGradient = LinearGradient(
colors: [Color(0xFF2BAFFE), Color(0xFF1C96F6), Color(0xFF0B7DEE)],
);
/// 扫描框:横向长方形,高度收矮,避免挤压下方两个功能药丸
static const double _frameWidth = 220;
static const double _frameHeight = 140;
@override
void dispose() {
_scanLineController.dispose();
_snController.dispose();
_controller.dispose();
super.dispose();
}
/// 与旧页逐行一致:识别到码值后 pop 回传(防重复触发)
void _onDetect(BarcodeCapture capture) {
if (_isScanned) return;
final List<Barcode> barcodes = capture.barcodes;
if (barcodes.isNotEmpty) {
final String? code = barcodes.first.rawValue;
if (code != null && code.isNotEmpty) {
_isScanned = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.mounted && Navigator.canPop(context)) {
Navigator.pop(context, code);
}
});
}
}
}
/// 相册识别:选图后交同一控制器 analyzeImage 解码;
/// 解码结果走 barcodes 流 → _onDetect,与扫码共用同一 pop 契约
Future<void> _pickFromAlbum() async {
if (_isScanned) return;
final XFile? file = await ImagePicker().pickImage(
source: ImageSource.gallery,
);
if (file == null) return;
final ok = await _controller.analyzeImage(file.path);
if (!ok && mounted) {
CapsuleToast.show('未识别到二维码,请换一张清晰图片');
}
}
/// 手动 SN 提交:与扫码同一 pop 契约回传
void _submitManualSn() {
if (_isScanned) return;
final sn = _snController.text.trim();
if (sn.isEmpty) {
CapsuleToast.show('请输入设备 SN');
return;
}
_isScanned = true;
if (Navigator.canPop(context)) {
Navigator.pop(context, sn);
}
}
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
),
child: Scaffold(
backgroundColor: const Color(0xFFFAFCFF),
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFFF5FAFF), Color(0xFFE9F2FC), Color(0xFFDDEAF8)],
),
),
child: SafeArea(
child: Column(
children: [
_buildTopBar(),
_buildSteps(),
Expanded(
// 整页不滚动:扫码卡吸收剩余高度,其余区块固定紧凑尺寸
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 16),
child: Column(
children: [
_buildTitleBlock(),
const SizedBox(height: 10),
Expanded(child: _buildScanCard()),
const SizedBox(height: 12),
_buildDividerHint(),
const SizedBox(height: 10),
_buildSnInput(),
const SizedBox(height: 12),
_buildPrimaryButton(),
const SizedBox(height: 12),
_buildSkipCard(),
],
),
),
),
],
),
),
),
),
);
}
// ===== 顶栏:返回 + 标题 + 暂时跳过 =====
Widget _buildTopBar() {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
child: Row(
children: [
GestureDetector(
onTap: () {
debugPrint('⬅️ [QrScannerV2] 返回');
Navigator.of(context).pop();
},
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: _border),
),
child: const Icon(Icons.chevron_left, color: _blue, size: 24),
),
),
const SizedBox(width: 12),
const Expanded(
child: Text(
'添加机器人',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: _navy,
),
),
),
// 热区撑满顶栏高度:避免小文本点击不灵
GestureDetector(
onTap: () {
debugPrint('⏭️ [QrScannerV2] 暂时跳过');
Navigator.of(context).pop();
},
behavior: HitTestBehavior.opaque,
child: SizedBox(
height: 40,
child: Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Text(
'暂时跳过',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: _blue,
),
),
),
),
),
),
],
),
);
}
// ===== 步骤条:1 识别设备(当前)→ 2 确认信息 → 3 绑定激活 =====
Widget _buildSteps() {
return Padding(
padding: const EdgeInsets.fromLTRB(28, 6, 28, 0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildStep(1, '识别设备', true),
_buildStepLine(),
_buildStep(2, '确认信息', false),
_buildStepLine(),
_buildStep(3, '绑定激活', false),
],
),
);
}
Widget _buildStep(int index, String label, bool active) {
return Column(
children: [
Container(
width: 34,
height: 34,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: active ? const Color(0xFFD9EAFB) : Colors.transparent,
),
alignment: Alignment.center,
child: Container(
width: 26,
height: 26,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: active ? _blue : const Color(0xFFDDE4EC),
),
alignment: Alignment.center,
child: Text(
'$index',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: active ? Colors.white : _gray,
),
),
),
),
const SizedBox(height: 4),
Text(
label,
style: TextStyle(
fontSize: 11,
fontWeight: active ? FontWeight.w600 : FontWeight.w400,
color: active ? _blue : _gray,
),
),
],
);
}
Widget _buildStepLine() {
return Expanded(
child: Padding(
// 对齐圆圈中线(外圈 40 高 → 中线 20)
padding: const EdgeInsets.fromLTRB(8, 16, 8, 0),
child: Container(height: 2, color: const Color(0xFFD8E2EE)),
),
);
}
// ===== 标题区 =====
Widget _buildTitleBlock() {
return const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'扫描设备二维码',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: _navy),
),
SizedBox(height: 4),
Text(
'将机器人机身上的二维码放入扫描框内',
style: TextStyle(fontSize: 12, color: _gray),
),
],
);
}
// ===== 扫码卡:相机预览 + 扫描框/扫描线 + 闪光灯/相册识别 =====
Widget _buildScanCard() {
return ClipRRect(
borderRadius: BorderRadius.circular(16),
child: Stack(
fit: StackFit.expand,
children: [
// 相机预览:与旧页同一控制器与回调
MobileScanner(controller: _controller, onDetect: _onDetect),
// 设计稿浅蓝罩色,让预览融入浅色页面
Container(color: _blue.withValues(alpha: 0.08)),
// 扫描框区与药丸区上下分区:长方形扫描框不会挤压药丸
Column(
children: [
Expanded(
child: Center(
child: SizedBox(
width: _frameWidth,
height: _frameHeight,
child: Stack(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: _blue.withValues(alpha: 0.25),
),
borderRadius: BorderRadius.circular(8),
),
),
_buildCorner(Alignment.topLeft),
_buildCorner(Alignment.topRight),
_buildCorner(Alignment.bottomLeft),
_buildCorner(Alignment.bottomRight),
AnimatedBuilder(
animation: _scanLineController,
builder: (context, _) => Positioned(
left: 6,
right: 6,
top:
8 +
(_frameHeight - 18) *
_scanLineController.value,
child: Container(
height: 2,
decoration: BoxDecoration(
color: _blue,
boxShadow: [
BoxShadow(
color: _blue.withValues(alpha: 0.5),
blurRadius: 6,
),
],
),
),
),
),
],
),
),
),
),
// 底部功能药丸:独立分区,不被扫描框挤压
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 14),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildPill(
Icons.bolt_rounded,
'闪光灯',
() async => _controller.toggleTorch(),
),
const SizedBox(width: 12),
_buildPill(
Icons.photo_library_outlined,
'相册识别',
_pickFromAlbum,
),
],
),
),
],
),
],
),
);
}
/// 扫描框四角蓝色折角
Widget _buildCorner(Alignment alignment) {
const len = 34.0;
const width = 4.0;
final isTop = alignment == Alignment.topLeft || alignment == Alignment.topRight;
final isLeft = alignment == Alignment.topLeft || alignment == Alignment.bottomLeft;
return Positioned(
top: isTop ? 0 : null,
bottom: isTop ? null : 0,
left: isLeft ? 0 : null,
right: isLeft ? null : 0,
child: Container(
width: len,
height: len,
decoration: BoxDecoration(
border: Border(
top: isTop ? const BorderSide(color: _blue, width: width) : BorderSide.none,
bottom: isTop ? BorderSide.none : const BorderSide(color: _blue, width: width),
left: isLeft ? const BorderSide(color: _blue, width: width) : BorderSide.none,
right: isLeft ? BorderSide.none : const BorderSide(color: _blue, width: width),
),
borderRadius: BorderRadius.only(
topLeft: isTop && isLeft ? const Radius.circular(8) : Radius.zero,
topRight: isTop && !isLeft ? const Radius.circular(8) : Radius.zero,
bottomLeft: !isTop && isLeft ? const Radius.circular(8) : Radius.zero,
bottomRight: !isTop && !isLeft ? const Radius.circular(8) : Radius.zero,
),
),
),
);
}
Widget _buildPill(IconData icon, String label, VoidCallback onTap) {
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 22, vertical: 11),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(22),
boxShadow: [
BoxShadow(
color: _navy.withValues(alpha: 0.08),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 18, color: _blue),
const SizedBox(width: 6),
Text(
label,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: _navy,
),
),
],
),
),
);
}
// ===== 「或手动输入 SN」分隔线 =====
Widget _buildDividerHint() {
return Row(
children: [
Expanded(child: Container(height: 1, color: const Color(0xFFDCE6F2))),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: Text('或手动输入 SN', style: TextStyle(fontSize: 11, color: _gray)),
),
Expanded(child: Container(height: 1, color: const Color(0xFFDCE6F2))),
],
);
}
// ===== 手动 SN 输入框:与登录页 V2 输入框同款(filled 白底 + 外轮廓描边,聚焦变蓝) =====
Widget _buildSnInput() {
return TextField(
controller: _snController,
style: const TextStyle(fontSize: 14, color: _navy),
cursorColor: _blue,
decoration: InputDecoration(
hintText: '请输入设备 SN,如 SA260002',
hintStyle: const TextStyle(color: _gray, fontSize: 14),
filled: true,
fillColor: Colors.white,
prefixIcon: const Icon(Icons.keyboard_outlined, size: 20, color: _blue),
prefixIconConstraints: const BoxConstraints(minWidth: 44, minHeight: 48),
contentPadding: const EdgeInsets.symmetric(vertical: 12),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: Color(0xFFE5EDF7)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: _blue, width: 1.2),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: Color(0xFFE5EDF7)),
),
),
);
}
// ===== 主按钮:识别设备 =====
Widget _buildPrimaryButton() {
return GestureDetector(
onTap: _submitManualSn,
child: Container(
height: 46,
decoration: BoxDecoration(
gradient: _btnGradient,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: _blue.withValues(alpha: 0.3),
blurRadius: 12,
offset: const Offset(0, 4),
),
],
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.center_focus_strong, size: 18, color: Colors.white),
SizedBox(width: 8),
Text(
'识别设备',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
],
),
),
);
}
// ===== 底部提示卡:机器人还没到货?暂时跳过 =====
Widget _buildSkipCard() {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFFEAF3FC),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: const Color(0xFFD9E8F8)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 38,
height: 38,
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: const Icon(Icons.access_time_rounded, size: 18, color: _blue),
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'机器人还没到货?',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: _navy,
),
),
const SizedBox(height: 4),
const Text(
'可以先体验 APP,收到设备后再添加',
style: TextStyle(fontSize: 11, color: _gray),
),
const SizedBox(height: 8),
GestureDetector(
onTap: () {
debugPrint('⏭️ [QrScannerV2] 暂时跳过,稍后添加');
Navigator.of(context).pop();
},
behavior: HitTestBehavior.opaque,
child: const Padding(
padding: EdgeInsets.symmetric(vertical: 4),
child: Text(
'暂时跳过,稍后添加 →',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: _blue,
),
),
),
),
],
),
),
],
),
);
}
}

View File

@@ -20,7 +20,7 @@ import '../bloc/robot_list_event.dart';
import '../bloc/robot_list_state.dart';
import '../widgets/robot_item_card.dart';
import 'ble_device_detail_page.dart';
import 'robot_control_page.dart';
import 'device_detail_page_v2.dart';
import 'cleaning_weeding_robot_task_page.dart';
/// 机器人列表页面
@@ -691,7 +691,9 @@ class _RobotListViewState extends State<RobotListView> {
return;
}
// hasHost == true → 走原来的逻辑
// hasHost == true → 走原来的逻辑:前置(setTargetDevice)不变,
// 跳转目标换成新设备详情页(V2 概览设计稿);
// 页内铃铛/远程遥控再回旧 RobotControlPage,方便新旧对照。
debugPrint('✅ [RobotListPage] hasHost=true,走正常控制流程');
// 1. 将当前机器人设置为全局待控制设备(用 robot.name 作为 deviceName)
@@ -711,22 +713,12 @@ class _RobotListViewState extends State<RobotListView> {
remoteCubit.setTargetDevice(device); // 🔥 TCP连接在后台异步执行
debugPrint('✅ [RobotListPage] setTargetDevice 已调用(TCP连接中)');
// 2. 跳转到机器人控制页面
final robotMap = {
'name': robot.name,
'id': robot.id,
'alias': robot.alias, // 传递别名
'type': robot.type,
'status': robot.status,
'battery': robot.battery,
'task': robot.task,
};
// 2. 跳转到新设备详情页
debugPrint('🚀 [RobotListPage] 准备跳转页面...');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RobotControlPage(robot: robotMap),
builder: (context) => DeviceDetailPageV2(robot: robot),
),
);
},

View File

@@ -23,6 +23,16 @@ class DeviceV2Display {
/// 版本后缀:PLUS 智能版 / STD 标准版 / PRO 旗舰版
static String editionOf(String key) => _editions[_seed(key) % _editions.length];
/// 版本占位:v2.x.y(后端暂无版本字段,集中概览表格用)
static String versionOf(String key) =>
'v2.${_seed(key) % 4}.${_seed(key) ~/ 4 % 10}';
static const _locations = ['1号厂房', '2号厂房', '原料区', '综合楼'];
/// 位置占位:后端暂无位置字段,集中概览表格用
static String locationOf(String key) =>
_locations[_seed(key) % _locations.length];
/// SN 掩码展示:前4 · · · 后2
static String maskedSn(String key) {
if (key.length <= 6) return key.toUpperCase();

View File

@@ -464,7 +464,10 @@ class LocalCameraCubit extends Cubit<LocalCameraState>
Future<void> tryCmd(List<String> args) async {
if (native is! NativePlayer) return;
try {
await native.command(args);
// 动态派发:web 编译时 NativePlayer 解析为 stub.dart(无 command 方法),
// 静态成员解析会直接编译失败;改 dynamic 把检查推迟到运行时——
// web 端 _usesMediaKit=false 永不进本分支,原生平台仍命中真 mpv 命令。
await (native as dynamic).command(args);
} catch (e) {
debugPrint('🎬 [iOS拉流] 忽略命令 $args:${e.runtimeType}');
}