import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:logger/web.dart'; import '/routes/app_routes.dart'; /// UI交互管理器 /// 负责处理所有与用户界面交互相关的功能 class UiManager { /// 显示更新确认对话框 /// [latestVersion] 最新版本号 /// [onConfirm] 确认更新的回调函数 void showUpdateDialog(String latestVersion, VoidCallback onConfirm) { Logger().d('显示更新对话框'); Get.dialog( AlertDialog( title: Text('发现新版本 $latestVersion'), content: const Text('是否立即更新?'), actions: [ TextButton( onPressed: () { Logger().d('取消按钮被点击'); Get.back(); }, child: const Text('取消'), ), TextButton( onPressed: () { Logger().d('更新按钮被点击'); Get.back(); Future.delayed(const Duration(milliseconds: 300)); onConfirm(); }, child: const Text('更新'), ), ], ), ); } /// 显示升级成功对话框 /// 引导用户进行设备重新配对 void showUpgradeSuccessDialog() { Get.dialog( AlertDialog( title: Row( children: [ Icon( Icons.check_circle, color: Colors.green[600], size: 28, ), SizedBox(width: 12.w), Text( '升级成功', style: TextStyle( color: Colors.green[700], fontWeight: FontWeight.w600, ), ), ], ), content: const Text( '固件升级已完成!\n\n设备需要重新配对才能正常使用,现在跳转到配对页面吗?', style: TextStyle( fontSize: 16, height: 1.4, ), ), actions: [ TextButton( onPressed: () { Get.back(); }, child: Text( '稍后配对', style: TextStyle(color: Colors.grey[600]), ), ), ElevatedButton( onPressed: () { Get.back(); Get.toNamed(Routes.pairing); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.green[600], foregroundColor: Colors.white, ), child: const Text('立即配对'), ), ], shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), barrierDismissible: false, ); } /// 显示错误提示 /// [title] 错误标题 /// [message] 错误信息 /// [backgroundColor] 背景颜色,可选 void showErrorSnackbar(String title, String message, {Color? backgroundColor}) { Get.snackbar( title, message, snackPosition: SnackPosition.BOTTOM, backgroundColor: backgroundColor ?? Colors.red[600], colorText: Colors.white, icon: const Icon( Icons.error_outline, color: Colors.white, ), ); } }