使用说明 完成
This commit is contained in:
@@ -30,9 +30,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_deviceName = (widget.device?.deviceAlias?.trim().isEmpty ?? true)
|
||||
? '未知设备'
|
||||
: widget.device!.deviceAlias!;
|
||||
_deviceName = (widget.device?.deviceAlias?.trim().isEmpty ?? true) ? '未知设备' : widget.device!.deviceAlias!;
|
||||
_deviceId = widget.device?.deviceName ?? '';
|
||||
_nameController = TextEditingController(text: _deviceName);
|
||||
}
|
||||
@@ -41,19 +39,16 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
// 兜底关闭所有弹窗
|
||||
if (_loadingDialogContext != null &&
|
||||
Navigator.canPop(_loadingDialogContext!)) {
|
||||
if (_loadingDialogContext != null && Navigator.canPop(_loadingDialogContext!)) {
|
||||
Navigator.pop(_loadingDialogContext!);
|
||||
}
|
||||
if (_updateLoadingContext != null &&
|
||||
Navigator.canPop(_updateLoadingContext!)) {
|
||||
if (_updateLoadingContext != null && Navigator.canPop(_updateLoadingContext!)) {
|
||||
Navigator.pop(_updateLoadingContext!);
|
||||
}
|
||||
if (_dialogContext != null && Navigator.canPop(_dialogContext!)) {
|
||||
Navigator.pop(_dialogContext!);
|
||||
}
|
||||
if (_editNameSheetContext != null &&
|
||||
Navigator.canPop(_editNameSheetContext!)) {
|
||||
if (_editNameSheetContext != null && Navigator.canPop(_editNameSheetContext!)) {
|
||||
Navigator.pop(_editNameSheetContext!);
|
||||
}
|
||||
super.dispose();
|
||||
@@ -65,35 +60,21 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
Future<void> bottomSheetFuture = showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
|
||||
builder: (ctx) {
|
||||
_editNameSheetContext = ctx;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20,
|
||||
right: 20,
|
||||
top: 20,
|
||||
bottom: MediaQuery.of(ctx).viewInsets.bottom + 20,
|
||||
),
|
||||
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 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(),
|
||||
counterText: "",
|
||||
),
|
||||
decoration: const InputDecoration(hintText: "请输入设备名称", border: OutlineInputBorder(), counterText: ""),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
@@ -116,9 +97,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
final text = _nameController.text.trim();
|
||||
if (text.isEmpty) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("名称不能为空")),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("名称不能为空")));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -130,14 +109,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
await _executeUpdateDeviceName(text);
|
||||
},
|
||||
child: _isUpdatingName
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
: const Text("确认修改"),
|
||||
),
|
||||
),
|
||||
@@ -171,8 +143,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
// 核心:返回上一页
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
final username =
|
||||
context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
final username = context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
}
|
||||
},
|
||||
@@ -196,17 +167,13 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
backgroundColor: const Color(0xFFF5F5F5),
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: const Text(
|
||||
'设备详情',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
title: const Text('设备详情', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
final username =
|
||||
context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
final username = context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
}
|
||||
},
|
||||
@@ -240,13 +207,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.1), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -255,30 +216,19 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
width: 300,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(
|
||||
Icons.device_hub,
|
||||
size: 100,
|
||||
color: Colors.grey,
|
||||
);
|
||||
return const Icon(Icons.device_hub, size: 100, color: Colors.grey);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: device.isOnline
|
||||
? const Color(0xFF00C853).withOpacity(0.1)
|
||||
: const Color(0xFF999999).withOpacity(0.1),
|
||||
color: device.isOnline ? const Color(0xFF00C853).withOpacity(0.1) : const Color(0xFF999999).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
device.isOnline ? '在线' : '离线',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: device.isOnline
|
||||
? const Color(0xFF00C853)
|
||||
: const Color(0xFF999999),
|
||||
),
|
||||
style: TextStyle(fontSize: 14, color: device.isOnline ? const Color(0xFF00C853) : const Color(0xFF999999)),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -294,23 +244,14 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.1), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(bottom: 16),
|
||||
child: Text(
|
||||
'基本信息',
|
||||
style: TextStyle(fontSize: 14, color: Color(0xFF999999)),
|
||||
),
|
||||
child: Text('基本信息', style: TextStyle(fontSize: 14, color: Color(0xFF999999))),
|
||||
),
|
||||
_buildInfoRow(
|
||||
context: context,
|
||||
@@ -346,21 +287,14 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
textAlign: TextAlign.right,
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.visible,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black87),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
GestureDetector(
|
||||
onTap: () => _copyToClipboard(deviceId, '设备ID已复制到剪贴板'),
|
||||
child: const Icon(
|
||||
Icons.copy,
|
||||
size: 16,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
child: const Icon(Icons.copy, size: 16, color: Color(0xFF999999)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -377,23 +311,14 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.1), blurRadius: 8, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(bottom: 16),
|
||||
child: Text(
|
||||
'资源中心',
|
||||
style: TextStyle(fontSize: 14, color: Color(0xFF999999)),
|
||||
),
|
||||
child: Text('资源中心', style: TextStyle(fontSize: 14, color: Color(0xFF999999))),
|
||||
),
|
||||
_buildResourceItem('使用说明', Icons.description_outlined),
|
||||
const Divider(height: 32, color: Color(0xFFF0F0F0)),
|
||||
@@ -404,12 +329,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
}
|
||||
|
||||
/// 通用信息行组件(保持不变)
|
||||
Widget _buildInfoRow({
|
||||
required BuildContext context,
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required Widget trailing,
|
||||
}) {
|
||||
Widget _buildInfoRow({required BuildContext context, required IconData icon, required String label, required Widget trailing}) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 18, color: const Color(0xFF999999)),
|
||||
@@ -425,9 +345,11 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
Widget _buildResourceItem(String title, IconData icon) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('暂未开放$title功能')));
|
||||
if (title == "使用说明") {
|
||||
context.go(RoutePaths.productDesc);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('暂未开放$title功能')));
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -435,11 +357,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
const SizedBox(width: 12),
|
||||
Text(title, style: const TextStyle(fontSize: 16)),
|
||||
const Spacer(),
|
||||
const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 16,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
const Icon(Icons.arrow_forward_ios, size: 16, color: Color(0xFF999999)),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -454,9 +372,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: const Color(0xFFFF3B30),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
side: const BorderSide(color: Color(0xFFFF3B30), width: 1),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
textStyle: const TextStyle(height: 1.2),
|
||||
@@ -468,11 +384,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
children: [
|
||||
Icon(Icons.unarchive_outlined, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'解绑设备',
|
||||
style: TextStyle(fontSize: 16, height: 1.0),
|
||||
overflow: TextOverflow.visible,
|
||||
),
|
||||
Text('解绑设备', style: TextStyle(fontSize: 16, height: 1.0), overflow: TextOverflow.visible),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -488,18 +400,11 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
return AlertDialog(
|
||||
title: const Text('确认解绑'),
|
||||
content: Text('确定要解绑【$_deviceName】吗?解绑后将无法管理该设备'),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(dialogContext), child: const Text('取消')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: const Color(0xFFFF3B30),
|
||||
),
|
||||
style: TextButton.styleFrom(foregroundColor: const Color(0xFFFF3B30)),
|
||||
onPressed: _executeUnbind,
|
||||
child: const Text('确认'),
|
||||
),
|
||||
@@ -512,12 +417,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
Future<void> _executeUnbind() async {
|
||||
if (_deviceId.isEmpty || _deviceName.isEmpty) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("设备信息异常,无法解绑"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("设备信息异常,无法解绑"), backgroundColor: Colors.red));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -535,15 +435,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
barrierDismissible: false,
|
||||
builder: (ctx) {
|
||||
_loadingDialogContext = ctx;
|
||||
return const AlertDialog(
|
||||
content: Row(
|
||||
children: [
|
||||
CircularProgressIndicator(strokeWidth: 2),
|
||||
SizedBox(width: 16),
|
||||
Text("正在解绑设备..."),
|
||||
],
|
||||
),
|
||||
);
|
||||
return const AlertDialog(content: Row(children: [CircularProgressIndicator(strokeWidth: 2), SizedBox(width: 16), Text("正在解绑设备...")]));
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -552,22 +444,15 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
await context.read<DevicesCubit>().unbindDevice(_deviceId, _deviceName);
|
||||
|
||||
// 主动关闭加载弹窗
|
||||
if (_loadingDialogContext != null &&
|
||||
Navigator.canPop(_loadingDialogContext!)) {
|
||||
if (_loadingDialogContext != null && Navigator.canPop(_loadingDialogContext!)) {
|
||||
Navigator.pop(_loadingDialogContext!);
|
||||
_loadingDialogContext = null;
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("解绑异常:${e.toString()}"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("解绑异常:${e.toString()}"), backgroundColor: Colors.red));
|
||||
// 关闭加载弹窗
|
||||
if (_loadingDialogContext != null &&
|
||||
Navigator.canPop(_loadingDialogContext!)) {
|
||||
if (_loadingDialogContext != null && Navigator.canPop(_loadingDialogContext!)) {
|
||||
Navigator.pop(_loadingDialogContext!);
|
||||
_loadingDialogContext = null;
|
||||
}
|
||||
@@ -580,12 +465,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
// 基础校验
|
||||
if (_deviceId.isEmpty || newDeviceName.isEmpty) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("设备信息异常,无法修改名称"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("设备信息异常,无法修改名称"), backgroundColor: Colors.red));
|
||||
}
|
||||
setState(() => _isUpdatingName = false);
|
||||
return;
|
||||
@@ -599,31 +479,17 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
barrierDismissible: false,
|
||||
builder: (ctx) {
|
||||
_updateLoadingContext = ctx;
|
||||
return const AlertDialog(
|
||||
content: Row(
|
||||
children: [
|
||||
CircularProgressIndicator(strokeWidth: 2),
|
||||
SizedBox(width: 16),
|
||||
Text("正在修改名称..."),
|
||||
],
|
||||
),
|
||||
);
|
||||
return const AlertDialog(content: Row(children: [CircularProgressIndicator(strokeWidth: 2), SizedBox(width: 16), Text("正在修改名称...")]));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
print(
|
||||
"调用updateDeviceName,deviceId: $_deviceId, newDeviceName: $newDeviceName",
|
||||
);
|
||||
print("调用updateDeviceName,deviceId: $_deviceId, newDeviceName: $newDeviceName");
|
||||
// 调用Cubit修改方法
|
||||
await context.read<DevicesCubit>().updateDeviceName(
|
||||
_deviceId,
|
||||
newDeviceName,
|
||||
);
|
||||
await context.read<DevicesCubit>().updateDeviceName(_deviceId, newDeviceName);
|
||||
|
||||
// 主动关闭修改名称加载弹窗
|
||||
if (_updateLoadingContext != null &&
|
||||
Navigator.canPop(_updateLoadingContext!)) {
|
||||
if (_updateLoadingContext != null && Navigator.canPop(_updateLoadingContext!)) {
|
||||
Navigator.pop(_updateLoadingContext!);
|
||||
_updateLoadingContext = null;
|
||||
}
|
||||
@@ -632,24 +498,13 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
|
||||
// 兜底:强制将Cubit的isLoading置为false
|
||||
if (context.mounted) {
|
||||
context.read<DevicesCubit>().emit(
|
||||
context.read<DevicesCubit>().state.copyWith(
|
||||
isLoading: false,
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
context.read<DevicesCubit>().emit(context.read<DevicesCubit>().state.copyWith(isLoading: false, operationType: DeviceOperationType.none));
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("修改异常:${e.toString()}"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("修改异常:${e.toString()}"), backgroundColor: Colors.red));
|
||||
// 关闭修改名称加载弹窗
|
||||
if (_updateLoadingContext != null &&
|
||||
Navigator.canPop(_updateLoadingContext!)) {
|
||||
if (_updateLoadingContext != null && Navigator.canPop(_updateLoadingContext!)) {
|
||||
Navigator.pop(_updateLoadingContext!);
|
||||
_updateLoadingContext = null;
|
||||
}
|
||||
@@ -658,12 +513,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
|
||||
// 兜底:强制重置Cubit的loading状态
|
||||
if (context.mounted) {
|
||||
context.read<DevicesCubit>().emit(
|
||||
context.read<DevicesCubit>().state.copyWith(
|
||||
isLoading: false,
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
context.read<DevicesCubit>().emit(context.read<DevicesCubit>().state.copyWith(isLoading: false, operationType: DeviceOperationType.none));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -671,38 +521,25 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
/// 处理解绑结果(保持不变)
|
||||
void _handleUnbindResult(DevicesState state) {
|
||||
// 强制关闭加载弹窗
|
||||
if (_loadingDialogContext != null &&
|
||||
Navigator.canPop(_loadingDialogContext!)) {
|
||||
if (_loadingDialogContext != null && Navigator.canPop(_loadingDialogContext!)) {
|
||||
Navigator.pop(_loadingDialogContext!);
|
||||
_loadingDialogContext = null;
|
||||
} else if (!state.isLoading &&
|
||||
context.mounted &&
|
||||
Navigator.canPop(context)) {
|
||||
} else if (!state.isLoading && context.mounted && Navigator.canPop(context)) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
if (state.errorMessage?.isEmpty == true && !state.isLoading) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("设备「$_deviceName」解绑成功"),
|
||||
backgroundColor: Colors.green,
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text("设备「$_deviceName」解绑成功"), backgroundColor: Colors.green, duration: const Duration(seconds: 2)));
|
||||
|
||||
final username =
|
||||
context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
final username = context.read<AppUserCubit>().state.user?.username ?? "";
|
||||
context.read<DevicesCubit>().fetchAllDevices(username);
|
||||
}
|
||||
} else if (state.errorMessage?.isNotEmpty == true && !state.isLoading) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("解绑失败:${state.errorMessage ?? '未知错误'}"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("解绑失败:${state.errorMessage ?? '未知错误'}"), backgroundColor: Colors.red));
|
||||
}
|
||||
}
|
||||
context.go(RoutePaths.home);
|
||||
@@ -711,8 +548,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
/// 处理修改名称结果(核心修改:放宽判断条件)
|
||||
void _handleUpdateNameResult(DevicesState state) {
|
||||
// 强制关闭修改名称加载弹窗(优先用专属上下文)
|
||||
if (_updateLoadingContext != null &&
|
||||
Navigator.canPop(_updateLoadingContext!)) {
|
||||
if (_updateLoadingContext != null && Navigator.canPop(_updateLoadingContext!)) {
|
||||
Navigator.pop(_updateLoadingContext!);
|
||||
_updateLoadingContext = null;
|
||||
}
|
||||
@@ -735,45 +571,25 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
});
|
||||
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("设备名称已修改为:$_deviceName"),
|
||||
backgroundColor: Colors.green,
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text("设备名称已修改为:$_deviceName"), backgroundColor: Colors.green, duration: const Duration(seconds: 2)));
|
||||
|
||||
// 关闭修改名称的底部抽屉(如果还在)
|
||||
if (_editNameSheetContext != null &&
|
||||
Navigator.canPop(_editNameSheetContext!)) {
|
||||
if (_editNameSheetContext != null && Navigator.canPop(_editNameSheetContext!)) {
|
||||
Navigator.pop(_editNameSheetContext!);
|
||||
_editNameSheetContext = null;
|
||||
}
|
||||
|
||||
// 强制重置Cubit的loading状态
|
||||
context.read<DevicesCubit>().emit(
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
context.read<DevicesCubit>().emit(state.copyWith(isLoading: false, operationType: DeviceOperationType.none));
|
||||
}
|
||||
} else if (state.errorMessage?.isNotEmpty == true) {
|
||||
setState(() => _isUpdatingName = false);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("修改失败:${state.errorMessage ?? '未知错误'}"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("修改失败:${state.errorMessage ?? '未知错误'}"), backgroundColor: Colors.red));
|
||||
// 强制重置Cubit的loading状态
|
||||
context.read<DevicesCubit>().emit(
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
operationType: DeviceOperationType.none,
|
||||
),
|
||||
);
|
||||
context.read<DevicesCubit>().emit(state.copyWith(isLoading: false, operationType: DeviceOperationType.none));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -782,9 +598,7 @@ class _MachineDetailsPageState extends State<MachineDetailsPage> {
|
||||
void _copyToClipboard(String text, String tip) {
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(tip), duration: const Duration(seconds: 1)),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(tip), duration: const Duration(seconds: 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user