Browse Source

feat(ota_upgrade): 添加设备详细信息显示并优化布局间距

- 新增设备详细信息卡片,显示设备型号和左右耳电量
- 调整各组件间距和padding值,优化整体布局
- 引入BleManager服务获取设备信息
newdev_shunjiawei
lxm 1 year ago
parent
commit
257eb1af99
  1. 222
      lib/modules/ota_upgrade/views/ota_upgrade_view.dart

222
lib/modules/ota_upgrade/views/ota_upgrade_view.dart

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/ota_upgrade_controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../data/services/ble_manager.dart';
class OtaUpgradeView extends GetView<OtaUpgradeController> {
const OtaUpgradeView({Key? key}) : super(key: key);
@ -89,17 +90,16 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
),
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.h),
padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 设备信息卡片 - 优化后的版本
_buildDeviceCard(isDarkMode),
SizedBox(height: 24.h),
SizedBox(height: 16.h),
// 更新说明 - 当有可用更新时显示
//_buildUpdateNotes(isDarkMode),
SizedBox(height: 16.h),
// 状态显示区域
Obx(() {
@ -150,12 +150,15 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
],
),
child: Padding(
padding: EdgeInsets.all(24.w),
padding: EdgeInsets.all(20.w),
child: Column(
children: [
// 设备图标区域
_buildDeviceIcon(isDarkMode),
SizedBox(height: 24.h),
SizedBox(height: 16.h),
// 设备详细信息区域
_buildDeviceDetailInfo(isDarkMode),
SizedBox(height: 16.h),
// 版本信息区域
_buildVersionInfo(isDarkMode),
],
@ -167,7 +170,7 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
// 设备图标
Widget _buildDeviceIcon(bool isDarkMode) {
return Container(
padding: EdgeInsets.all(20.w),
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: isDarkMode
? Colors.white.withValues(alpha: 0.05)
@ -184,12 +187,193 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
isDarkMode
? 'assets/images/headphone_dark.png'
: 'assets/images/headphone_light.png',
height: 120.h,
height: 100.h,
fit: BoxFit.contain,
),
);
}
// 设备详细信息显示
Widget _buildDeviceDetailInfo(bool isDarkMode) {
return Obx(() {
final deviceInfo = Get.find<BleManager>().deviceInfo.value;
return Container(
padding: EdgeInsets.all(14.w),
decoration: BoxDecoration(
color: isDarkMode
? Colors.white.withValues(alpha: 0.03)
: Colors.white.withValues(alpha: 0.8),
borderRadius: BorderRadius.circular(12.r),
border: Border.all(
color: isDarkMode
? Colors.white.withValues(alpha: 0.08)
: Colors.grey.withValues(alpha: 0.2),
width: 1,
),
),
child: Column(
children: [
// 设备型号信息
_buildDeviceInfoRow(
icon: Icons.headset,
label: '设备型号',
value: deviceInfo?.name ?? '未知设备',
isDarkMode: isDarkMode,
),
SizedBox(height: 10.h),
// 电量信息区域
Row(
children: [
// 左耳电量
Expanded(
child: _buildBatteryInfo(
label: '左耳电量',
batteryLevel: deviceInfo?.leftEarBattery ?? 0,
isCharging: deviceInfo?.leftEarCharging ?? false,
isDarkMode: isDarkMode,
icon: Icons.headset,
),
),
SizedBox(width: 10.w),
// 右耳电量
Expanded(
child: _buildBatteryInfo(
label: '右耳电量',
batteryLevel: deviceInfo?.rightEarBattery ?? 0,
isCharging: deviceInfo?.rightEarCharging ?? false,
isDarkMode: isDarkMode,
icon: Icons.headset,
),
),
],
),
],
),
);
});
}
// 设备信息行组件
Widget _buildDeviceInfoRow({
required IconData icon,
required String label,
required String value,
required bool isDarkMode,
}) {
return Row(
children: [
Container(
padding: EdgeInsets.all(6.w),
decoration: BoxDecoration(
color: isDarkMode
? Colors.blue.withValues(alpha: 0.1)
: Colors.blue.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(6.r),
),
child: Icon(
icon,
size: 16.sp,
color: isDarkMode ? Colors.blue[300] : Colors.blue[600],
),
),
SizedBox(width: 12.w),
Text(
label,
style: TextStyle(
fontSize: 14.sp,
color: isDarkMode ? Colors.grey[300] : Colors.grey[700],
fontWeight: FontWeight.w500,
),
),
const Spacer(),
Text(
value,
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w600,
color: isDarkMode ? Colors.white : Colors.black87,
),
),
],
);
}
// 电池信息组件
Widget _buildBatteryInfo({
required String label,
required int batteryLevel,
required bool isCharging,
required bool isDarkMode,
required IconData icon,
}) {
Color batteryColor;
if (batteryLevel > 60) {
batteryColor = Colors.green;
} else if (batteryLevel > 30) {
batteryColor = Colors.orange;
} else {
batteryColor = Colors.red;
}
return Container(
padding: EdgeInsets.all(10.w),
decoration: BoxDecoration(
color: isDarkMode
? batteryColor.withValues(alpha: 0.1)
: batteryColor.withValues(alpha: 0.05),
borderRadius: BorderRadius.circular(8.r),
border: Border.all(
color: batteryColor.withValues(alpha: 0.3),
width: 1,
),
),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
isCharging ? Icons.battery_charging_full : Icons.battery_std,
size: 16.sp,
color: batteryColor,
),
SizedBox(width: 4.w),
Text(
label,
style: TextStyle(
fontSize: 12.sp,
color: isDarkMode ? Colors.grey[300] : Colors.grey[700],
fontWeight: FontWeight.w500,
),
),
],
),
SizedBox(height: 4.h),
Text(
'${batteryLevel}%',
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.bold,
color: batteryColor,
),
),
if (isCharging) ...[
SizedBox(height: 1.h),
Text(
'充电中',
style: TextStyle(
fontSize: 10.sp,
color: batteryColor,
fontWeight: FontWeight.w500,
),
),
],
],
),
);
}
// 版本信息显示
Widget _buildVersionInfo(bool isDarkMode) {
return Column(
@ -201,7 +385,7 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
isDarkMode: isDarkMode,
isLatest: false,
),
SizedBox(height: 16.h),
SizedBox(height: 8.h),
// 最新版本信息
_buildVersionInfoRow(
label: '最新固件版本'.tr,
@ -210,7 +394,7 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
isLatest: true,
),
// 版本状态指示器
SizedBox(height: 20.h),
SizedBox(height: 14.h),
_buildVersionStatusIndicator(isDarkMode),
],
);
@ -224,7 +408,7 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
required bool isLatest,
}) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 10.h),
decoration: BoxDecoration(
color: isDarkMode
? Colors.white.withValues(alpha: 0.03)
@ -252,7 +436,8 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
children: [
if (isLatest && controller.isUpdateAvailable.value) ...[
Container(
padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h),
padding:
EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h),
decoration: BoxDecoration(
color: Colors.orange.withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(8.r),
@ -403,7 +588,9 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
),
child: Icon(
Icons.new_releases,
color: isDarkMode ? Colors.amber[300] : Colors.amber[700],
color: isDarkMode
? Colors.amber[300]
: Colors.amber[700],
size: 18.sp,
),
),
@ -413,7 +600,9 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: isDarkMode ? Colors.amber[200] : Colors.amber[800],
color: isDarkMode
? Colors.amber[200]
: Colors.amber[800],
),
),
],
@ -574,7 +763,8 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
),
),
style: ElevatedButton.styleFrom(
backgroundColor: isDarkMode ? const Color(0xFF0066CC) : Colors.blue,
backgroundColor:
isDarkMode ? const Color(0xFF0066CC) : Colors.blue,
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(vertical: 14.h),
shape: RoundedRectangleBorder(
@ -685,7 +875,9 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
'取出双耳机,并保证电量均为30%以上的状态'.tr,
style: TextStyle(
fontSize: 13.sp,
color: isDarkMode ? Colors.orange[200] : Colors.orange[800],
color: isDarkMode
? Colors.orange[200]
: Colors.orange[800],
height: 1.3,
),
),

Loading…
Cancel
Save