2026-02-25 13:41:23 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2026-02-26 16:38:10 +08:00
|
|
|
|
import 'package:flutter/services.dart';
|
2026-02-27 13:17:09 +08:00
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2026-02-27 14:16:29 +08:00
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
|
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
|
|
|
|
|
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
|
2026-02-26 16:38:10 +08:00
|
|
|
|
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
2026-02-27 13:17:09 +08:00
|
|
|
|
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart';
|
2026-02-27 14:16:29 +08:00
|
|
|
|
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_state.dart';
|
2026-02-25 13:41:23 +08:00
|
|
|
|
|
2026-02-26 20:36:28 +08:00
|
|
|
|
class MachineDetailsPage extends StatefulWidget {
|
|
|
|
|
|
final DeviceEntity? device;
|
2026-02-26 16:38:10 +08:00
|
|
|
|
|
|
|
|
|
|
const MachineDetailsPage({super.key, this.device});
|
2026-02-25 13:41:23 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
2026-02-26 20:36:28 +08:00
|
|
|
|
State<MachineDetailsPage> createState() => _MachineDetailsPageState();
|
2026-02-25 13:41:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-26 20:36:28 +08:00
|
|
|
|
class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
|
|
|
|
|
late TextEditingController _nameController;
|
|
|
|
|
|
late String _deviceName;
|
2026-02-27 13:17:09 +08:00
|
|
|
|
late String _deviceId;
|
2026-02-27 14:16:29 +08:00
|
|
|
|
BuildContext? _dialogContext;
|
2026-02-26 20:36:28 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
|
|
_deviceName = (widget.device?.deviceAlias?.trim().isEmpty ?? true)
|
|
|
|
|
|
? '未知设备'
|
|
|
|
|
|
: widget.device!.deviceAlias!;
|
2026-02-27 13:17:09 +08:00
|
|
|
|
_deviceId = widget.device?.deviceName ?? '';
|
2026-02-26 20:36:28 +08:00
|
|
|
|
|
|
|
|
|
|
_nameController = TextEditingController();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void dispose() {
|
|
|
|
|
|
_nameController.dispose();
|
|
|
|
|
|
super.dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 弹出修改设备名称底部抽屉
|
|
|
|
|
|
void _showEditNameSheet() {
|
|
|
|
|
|
_nameController.text = _deviceName;
|
|
|
|
|
|
|
|
|
|
|
|
showModalBottomSheet(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
|
|
|
|
),
|
|
|
|
|
|
builder: (ctx) {
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
|
|
left: 20,
|
|
|
|
|
|
right: 20,
|
|
|
|
|
|
top: 20,
|
|
|
|
|
|
bottom: MediaQuery.of(ctx).viewInsets.bottom + 20,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
const Text(
|
|
|
|
|
|
"修改设备名称",
|
|
|
|
|
|
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
TextField(
|
|
|
|
|
|
controller: _nameController,
|
|
|
|
|
|
autofocus: true,
|
|
|
|
|
|
maxLength: 20,
|
|
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
|
|
hintText: "请输入设备名称",
|
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
|
Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: OutlinedButton(
|
|
|
|
|
|
onPressed: () => Navigator.pop(ctx),
|
|
|
|
|
|
child: const Text("取消"),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: OutlinedButton(
|
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
final text = _nameController.text.trim();
|
|
|
|
|
|
|
|
|
|
|
|
if (text.isEmpty) {
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
|
const SnackBar(content: Text("名称不能为空")),
|
|
|
|
|
|
);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
_deviceName = text;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Navigator.pop(ctx);
|
2026-02-26 16:38:10 +08:00
|
|
|
|
|
2026-02-26 20:36:28 +08:00
|
|
|
|
ScaffoldMessenger.of(
|
|
|
|
|
|
context,
|
|
|
|
|
|
).showSnackBar(SnackBar(content: Text("已修改为:$text")));
|
|
|
|
|
|
},
|
|
|
|
|
|
child: const Text("确认"),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-02-25 13:41:23 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-02-26 20:36:28 +08:00
|
|
|
|
if (widget.device == null) {
|
2026-02-26 16:38:10 +08:00
|
|
|
|
return const Scaffold(body: Center(child: Text("未获取到设备信息")));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-26 20:36:28 +08:00
|
|
|
|
final currentDevice = widget.device!;
|
2026-02-27 14:16:29 +08:00
|
|
|
|
return BlocListener<DevicesCubit, DevicesState>(
|
|
|
|
|
|
listener: (context, state) {
|
|
|
|
|
|
// 只有解绑操作触发的状态变化才处理
|
|
|
|
|
|
if (state.isLoading || state.errorMessage != null) {
|
|
|
|
|
|
_handleUnbindResult(state);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
|
backgroundColor: const Color(0xFFF5F5F5),
|
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
|
title: const Text(
|
|
|
|
|
|
'设备详情',
|
|
|
|
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
|
|
|
|
),
|
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
|
icon: const Icon(Icons.arrow_back_ios),
|
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
|
),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
),
|
2026-02-27 14:16:29 +08:00
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
_buildDeviceStatusCard(currentDevice),
|
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
_buildBasicInfoCard(context, currentDevice), // 传递context和设备数据
|
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
_buildResourceCenterCard(),
|
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
|
_buildUnbindButton(context),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-26 20:36:28 +08:00
|
|
|
|
/// 设备状态卡片
|
2026-02-26 16:38:10 +08:00
|
|
|
|
Widget _buildDeviceStatusCard(DeviceEntity device) {
|
2026-02-25 13:41:23 +08:00
|
|
|
|
return Container(
|
|
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: [
|
2026-02-26 20:36:28 +08:00
|
|
|
|
Image.asset('assets/images/car.png', width: 300, fit: BoxFit.contain),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
const SizedBox(height: 12),
|
2026-02-26 16:38:10 +08:00
|
|
|
|
Text(
|
|
|
|
|
|
device.isOnline ? '在线' : '离线',
|
2026-02-25 13:41:23 +08:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
fontSize: 14,
|
2026-02-26 16:38:10 +08:00
|
|
|
|
color: device.isOnline
|
|
|
|
|
|
? const Color(0xFF00C853)
|
|
|
|
|
|
: const Color(0xFF999999),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-26 16:38:10 +08:00
|
|
|
|
// 基本信息卡片(接收context和设备数据参数)
|
|
|
|
|
|
Widget _buildBasicInfoCard(BuildContext context, DeviceEntity device) {
|
|
|
|
|
|
// 处理设备名称(空值兜底)
|
|
|
|
|
|
final deviceName = (device.deviceAlias?.trim() ?? '').isEmpty
|
|
|
|
|
|
? '未知设备'
|
|
|
|
|
|
: device.deviceAlias!;
|
|
|
|
|
|
// 处理设备ID(空值兜底)
|
|
|
|
|
|
final deviceId = device.deviceName ?? '未知ID';
|
|
|
|
|
|
|
2026-02-25 13:41:23 +08:00
|
|
|
|
return Container(
|
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
const Padding(
|
|
|
|
|
|
padding: EdgeInsets.only(bottom: 16),
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
'基本信息',
|
2026-02-26 16:38:10 +08:00
|
|
|
|
style: TextStyle(fontSize: 14, color: Color(0xFF999999)),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-02-26 16:38:10 +08:00
|
|
|
|
// 设备名称行 - 传递context参数
|
2026-02-25 13:41:23 +08:00
|
|
|
|
_buildInfoRow(
|
2026-02-26 16:38:10 +08:00
|
|
|
|
context: context, // 关键:补上必填的context参数
|
2026-02-25 13:41:23 +08:00
|
|
|
|
icon: Icons.info_outline,
|
|
|
|
|
|
label: '设备名称',
|
2026-02-26 20:36:28 +08:00
|
|
|
|
trailing: GestureDetector(
|
|
|
|
|
|
onTap: _showEditNameSheet,
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Text(_deviceName),
|
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
|
const Icon(Icons.edit, size: 16, color: Color(0xFF007AFF)),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const Divider(height: 32, color: Color(0xFFF0F0F0)),
|
2026-02-26 16:38:10 +08:00
|
|
|
|
// 设备ID行 - 传递context参数
|
|
|
|
|
|
// 设备ID行 - 传递context参数
|
2026-02-25 13:41:23 +08:00
|
|
|
|
_buildInfoRow(
|
2026-02-26 16:38:10 +08:00
|
|
|
|
context: context,
|
2026-02-25 13:41:23 +08:00
|
|
|
|
icon: Icons.shield_outlined,
|
|
|
|
|
|
label: '设备ID',
|
2026-02-26 16:38:10 +08:00
|
|
|
|
trailing: Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end, // 右对齐
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min, // 只占必要高度
|
|
|
|
|
|
children: [
|
|
|
|
|
|
// 核心修改:去掉宽度限制,允许换行显示全部ID
|
|
|
|
|
|
SizedBox(
|
|
|
|
|
|
// 取消固定宽度,让文本自适应(也可设置最大宽度适配屏幕)
|
|
|
|
|
|
width:
|
|
|
|
|
|
MediaQuery.of(context).size.width - 180, // 适配屏幕宽度(避免超出)
|
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
|
onLongPress: () {
|
|
|
|
|
|
// 长按文本复制
|
|
|
|
|
|
Clipboard.setData(ClipboardData(text: deviceId));
|
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
|
const SnackBar(
|
|
|
|
|
|
content: Text('设备ID已复制'),
|
|
|
|
|
|
duration: Duration(seconds: 1),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
deviceId,
|
|
|
|
|
|
textAlign: TextAlign.right, // 右对齐更美观
|
|
|
|
|
|
softWrap: true, // 允许换行
|
|
|
|
|
|
overflow: TextOverflow.visible, // 显示全部内容(无省略号)
|
|
|
|
|
|
|
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
|
color: Colors.black87,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(height: 4), // 文本和复制图标间距
|
|
|
|
|
|
// 复制图标单独一行
|
|
|
|
|
|
GestureDetector(
|
|
|
|
|
|
onTap: () {
|
|
|
|
|
|
Clipboard.setData(ClipboardData(text: deviceId));
|
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
|
const SnackBar(
|
|
|
|
|
|
content: Text('设备ID已复制到剪贴板'),
|
|
|
|
|
|
duration: Duration(seconds: 1),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
child: const Icon(
|
|
|
|
|
|
Icons.copy,
|
|
|
|
|
|
size: 16,
|
|
|
|
|
|
color: Color(0xFF999999),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
//_buildInfoRow(
|
|
|
|
|
|
// context: context, // 关键:补上必填的context参数
|
|
|
|
|
|
// icon: Icons.info_outline,
|
|
|
|
|
|
// label: '激活时间',
|
|
|
|
|
|
// trailing: Row(
|
|
|
|
|
|
// mainAxisSize: MainAxisSize.min, // 防止Row撑满宽度
|
|
|
|
|
|
// children: [
|
|
|
|
|
|
// // 显示真实设备名称
|
|
|
|
|
|
// Text(activeTime),
|
|
|
|
|
|
// const SizedBox(width: 8),
|
|
|
|
|
|
// const Icon(
|
|
|
|
|
|
// Icons.edit,
|
|
|
|
|
|
// size: 16,
|
|
|
|
|
|
// color: Color(0xFF007AFF),
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// ],
|
|
|
|
|
|
// ),
|
|
|
|
|
|
//),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-26 16:38:10 +08:00
|
|
|
|
// 资源中心卡片(无设备数据依赖)
|
2026-02-25 13:41:23 +08:00
|
|
|
|
Widget _buildResourceCenterCard() {
|
|
|
|
|
|
return Container(
|
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
const Padding(
|
|
|
|
|
|
padding: EdgeInsets.only(bottom: 16),
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
'资源中心',
|
2026-02-26 16:38:10 +08:00
|
|
|
|
style: TextStyle(fontSize: 14, color: Color(0xFF999999)),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
_buildResourceItem('使用说明', Icons.description_outlined),
|
|
|
|
|
|
const Divider(height: 32, color: Color(0xFFF0F0F0)),
|
|
|
|
|
|
_buildResourceItem('产品手册', Icons.book_outlined),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-26 16:38:10 +08:00
|
|
|
|
// 信息行组件(添加context必填参数)
|
2026-02-25 13:41:23 +08:00
|
|
|
|
Widget _buildInfoRow({
|
2026-02-26 16:38:10 +08:00
|
|
|
|
required BuildContext context, // 必填的context参数
|
2026-02-25 13:41:23 +08:00
|
|
|
|
required IconData icon,
|
|
|
|
|
|
required String label,
|
|
|
|
|
|
required Widget trailing,
|
|
|
|
|
|
}) {
|
|
|
|
|
|
return Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Icon(icon, size: 18, color: const Color(0xFF999999)),
|
|
|
|
|
|
const SizedBox(width: 12),
|
2026-02-26 16:38:10 +08:00
|
|
|
|
Text(label, style: const TextStyle(fontSize: 16)),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
const Spacer(),
|
|
|
|
|
|
trailing,
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 资源项组件
|
|
|
|
|
|
Widget _buildResourceItem(String title, IconData icon) {
|
|
|
|
|
|
return Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Icon(icon, size: 18, color: const Color(0xFF007AFF)),
|
|
|
|
|
|
const SizedBox(width: 12),
|
2026-02-26 16:38:10 +08:00
|
|
|
|
Text(title, style: const TextStyle(fontSize: 16)),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
const Spacer(),
|
|
|
|
|
|
const Icon(Icons.arrow_forward_ios, size: 16, color: Color(0xFF999999)),
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解绑设备按钮
|
|
|
|
|
|
Widget _buildUnbindButton(BuildContext context) {
|
|
|
|
|
|
return SizedBox(
|
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
|
height: 48,
|
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
|
foregroundColor: const Color(0xFFFF3B30),
|
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
// 实现解绑逻辑
|
|
|
|
|
|
showDialog(
|
|
|
|
|
|
context: context,
|
2026-02-26 16:38:10 +08:00
|
|
|
|
builder: (dialogContext) => AlertDialog(
|
2026-02-25 13:41:23 +08:00
|
|
|
|
title: const Text('确认解绑'),
|
2026-02-26 20:36:28 +08:00
|
|
|
|
content: Text('确定要解绑【${_deviceName ?? '该设备'}】吗?'),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
actions: [
|
|
|
|
|
|
TextButton(
|
2026-02-26 16:38:10 +08:00
|
|
|
|
onPressed: () => Navigator.pop(dialogContext),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
child: const Text('取消'),
|
|
|
|
|
|
),
|
|
|
|
|
|
TextButton(
|
2026-02-27 14:16:29 +08:00
|
|
|
|
onPressed: _executeUnbind, // 执行解绑
|
|
|
|
|
|
//onPressed: () {
|
|
|
|
|
|
|
|
|
|
|
|
// //Navigator.pop(dialogContext);
|
|
|
|
|
|
// //context.read<DevicesCubit>().unbindDevice(
|
|
|
|
|
|
// // _deviceId ?? '',
|
|
|
|
|
|
// // _deviceName ?? '',
|
|
|
|
|
|
// //);
|
|
|
|
|
|
// // 执行解绑操作(传入设备ID)
|
|
|
|
|
|
// // _unbindDevice(device?.deviceName ?? '');
|
|
|
|
|
|
//},
|
2026-02-25 13:41:23 +08:00
|
|
|
|
child: const Text('确认'),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
child: const Row(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Icon(Icons.unarchive_outlined, size: 18),
|
|
|
|
|
|
SizedBox(width: 12),
|
2026-02-26 16:38:10 +08:00
|
|
|
|
Text('解绑设备', style: TextStyle(fontSize: 12)),
|
2026-02-25 13:41:23 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-02-26 16:38:10 +08:00
|
|
|
|
|
2026-02-27 14:16:29 +08:00
|
|
|
|
Future<void> _executeUnbind() async {
|
|
|
|
|
|
if (_deviceId.isEmpty || _deviceName.isEmpty) {
|
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
|
const SnackBar(
|
|
|
|
|
|
content: Text("设备信息异常,无法解绑"),
|
|
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 调用 Cubit 解绑方法
|
|
|
|
|
|
await context.read<DevicesCubit>().unbindDevice(_deviceId, _deviceName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 处理解绑结果(成功/失败)
|
|
|
|
|
|
void _handleUnbindResult(DevicesState state) {
|
|
|
|
|
|
// 1. 关闭确认弹窗
|
|
|
|
|
|
if (_dialogContext != null && Navigator.canPop(_dialogContext!)) {
|
|
|
|
|
|
Navigator.pop(_dialogContext!);
|
|
|
|
|
|
_dialogContext = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 处理加载状态(隐藏加载弹窗/按钮禁用等)
|
|
|
|
|
|
if (state.isLoading) {
|
|
|
|
|
|
// 可选:显示加载弹窗
|
|
|
|
|
|
showDialog(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
barrierDismissible: false,
|
|
|
|
|
|
builder: (ctx) => const AlertDialog(
|
|
|
|
|
|
content: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
CircularProgressIndicator(),
|
|
|
|
|
|
SizedBox(width: 16),
|
|
|
|
|
|
Text("正在解绑设备..."),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 处理结果
|
|
|
|
|
|
if (state.errorMessage?.isEmpty == true) {
|
|
|
|
|
|
// 解绑成功
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
|
SnackBar(
|
|
|
|
|
|
content: Text("设备「$_deviceName」解绑成功"),
|
|
|
|
|
|
backgroundColor: Colors.green,
|
|
|
|
|
|
duration: const Duration(seconds: 2),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 延迟返回上一页(让用户看到提示)
|
|
|
|
|
|
Future.delayed(const Duration(seconds: 1), () {
|
|
|
|
|
|
if (context.mounted) {
|
|
|
|
|
|
Navigator.pop(context); // 返回设备列表页
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} else if (state.errorMessage?.isNotEmpty == true) {
|
|
|
|
|
|
// 解绑失败
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
|
SnackBar(
|
|
|
|
|
|
content: Text("解绑失败:${state.errorMessage ?? '未知错误'}"),
|
|
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭加载弹窗(如果存在)
|
|
|
|
|
|
if (Navigator.canPop(context)) {
|
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
final username = context.read<AppUserCubit>().state.user?.username ?? "";
|
|
|
|
|
|
context.read<DevicesCubit>().fetchAllDevices(username);
|
|
|
|
|
|
context.go(RoutePaths.home);
|
|
|
|
|
|
}
|
2026-02-25 13:41:23 +08:00
|
|
|
|
}
|