You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
687 lines
22 KiB
687 lines
22 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import '../controllers/home_controller.dart';
|
|
import '../../../core/widgets/common_bottom_nav.dart';
|
|
|
|
// 导入枚举
|
|
import '../controllers/home_controller.dart' show ConnectionStatus;
|
|
|
|
class HomeView extends GetView<HomeController> {
|
|
const HomeView({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.grey[50],
|
|
body: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
// 状态栏和标题区域
|
|
_buildHeader(),
|
|
|
|
// 主要内容区域(可滚动)
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
physics: const BouncingScrollPhysics(),
|
|
child: Padding(
|
|
padding: EdgeInsets.fromLTRB(16.w, 0, 16.w, 16.h),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 耳机图片
|
|
_buildEarbudsImage(),
|
|
|
|
// 设备状态卡片
|
|
SizedBox(height: 16.h),
|
|
_buildDeviceStatusCard(),
|
|
|
|
// AI功能部分
|
|
SizedBox(height: 16.h),
|
|
_buildAIFunctionsCard(),
|
|
|
|
// 固件更新提示
|
|
SizedBox(height: 16.h),
|
|
_buildFirmwareUpdateCard(),
|
|
|
|
// 快速功能访问
|
|
SizedBox(height: 24.h),
|
|
_buildQuickFunctions(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
bottomNavigationBar: const CommonBottomNav(currentIndex: 0),
|
|
);
|
|
}
|
|
|
|
// 页面顶部:状态栏和标题
|
|
Widget _buildHeader() {
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
|
|
child: Column(
|
|
children: [
|
|
// 删除状态栏
|
|
|
|
// 标题区域
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'DeepVoice Pro',
|
|
style: TextStyle(
|
|
fontSize: 20.sp,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.grey[800],
|
|
),
|
|
),
|
|
Container(
|
|
width: 32.w,
|
|
height: 32.w,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[200],
|
|
shape: BoxShape.circle,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.2),
|
|
blurRadius: 4,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: IconButton(
|
|
icon: Icon(Icons.more_horiz, size: 16.sp, color: Colors.grey[600]),
|
|
padding: EdgeInsets.zero,
|
|
onPressed: () {
|
|
// 打开更多选项菜单
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 耳机图片
|
|
Widget _buildEarbudsImage() {
|
|
return Container(
|
|
height: 180.h,
|
|
alignment: Alignment.center,
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.2),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
child: Container(
|
|
color: Colors.white,
|
|
padding: EdgeInsets.all(16.w),
|
|
child: Icon(
|
|
Icons.headset,
|
|
size: 120.sp,
|
|
color: Colors.blueGrey,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 设备状态卡片
|
|
Widget _buildDeviceStatusCard() {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
padding: EdgeInsets.all(16.w),
|
|
child: Column(
|
|
children: [
|
|
// 状态标题行
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'设备状态',
|
|
style: TextStyle(
|
|
fontSize: 14.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.grey[700],
|
|
),
|
|
),
|
|
Obx(() => Row(
|
|
children: [
|
|
Container(
|
|
width: 8.w,
|
|
height: 8.w,
|
|
decoration: BoxDecoration(
|
|
color: controller.getConnectionStatusColor(),
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
SizedBox(width: 4.w),
|
|
Text(
|
|
controller.getConnectionStatusText(),
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: controller.getConnectionStatusColor(),
|
|
),
|
|
),
|
|
// 添加刷新按钮
|
|
SizedBox(width: 8.w),
|
|
InkWell(
|
|
onTap: controller.refreshDeviceInfo,
|
|
child: Icon(
|
|
Icons.refresh,
|
|
size: 16.sp,
|
|
color: Colors.grey[600],
|
|
),
|
|
),
|
|
],
|
|
)),
|
|
],
|
|
),
|
|
|
|
// 设备信息
|
|
SizedBox(height: 12.h),
|
|
Obx(() {
|
|
// 如果连接失败且有错误信息,显示错误提示
|
|
if (controller.connectionStatus == ConnectionStatus.failed &&
|
|
controller.connectionErrorMsg.isNotEmpty) {
|
|
return Column(
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.all(8.w),
|
|
decoration: BoxDecoration(
|
|
color: Colors.red[50],
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
border: Border.all(color: Colors.red[200]!),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.error_outline,
|
|
color: Colors.red,
|
|
size: 16.sp,
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Expanded(
|
|
child: Text(
|
|
controller.connectionErrorMsg,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: Colors.red[800],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 12.h),
|
|
// 连接按钮
|
|
ElevatedButton(
|
|
onPressed: controller.rescanDevices,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue,
|
|
foregroundColor: Colors.white,
|
|
minimumSize: Size(double.infinity, 36.h),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
),
|
|
),
|
|
child: Text('重新连接'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 如果正在连接中,显示连接中提示
|
|
if (controller.connectionStatus == ConnectionStatus.connecting) {
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(vertical: 16.h),
|
|
child: Center(
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
width: 24.w,
|
|
height: 24.w,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2.w,
|
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
|
|
),
|
|
),
|
|
SizedBox(height: 8.h),
|
|
Text(
|
|
'正在连接设备...',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: Colors.blue,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
return controller.isConnected
|
|
? Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
'已连接到:${controller.getDeviceName()}',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.grey[700],
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h),
|
|
decoration: BoxDecoration(
|
|
color: Colors.blue.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(4.r),
|
|
),
|
|
child: Text(
|
|
'信号: ${controller.getSignalStrength()}',
|
|
style: TextStyle(
|
|
fontSize: 10.sp,
|
|
color: Colors.blue[700],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 8.h),
|
|
Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 6.h),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[50],
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'设备ID:${controller.getDeviceId()}',
|
|
style: TextStyle(
|
|
fontSize: 10.sp,
|
|
color: Colors.grey[500],
|
|
),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Text(
|
|
'固件版本:${controller.firmwareVersion}',
|
|
style: TextStyle(
|
|
fontSize: 10.sp,
|
|
color: Colors.grey[500],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: Container(
|
|
padding: EdgeInsets.symmetric(vertical: 8.h),
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[100],
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.bluetooth_disabled,
|
|
size: 14.sp,
|
|
color: Colors.grey[700],
|
|
),
|
|
SizedBox(width: 4.w),
|
|
Text(
|
|
'未连接设备,点击下方按钮连接',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
|
|
// 连接按钮(仅在未连接时显示)
|
|
SizedBox(height: 12.h),
|
|
Obx(() {
|
|
if (controller.connectionStatus == ConnectionStatus.disconnected) {
|
|
return ElevatedButton(
|
|
onPressed: controller.rescanDevices,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue,
|
|
foregroundColor: Colors.white,
|
|
minimumSize: Size(double.infinity, 36.h),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
),
|
|
),
|
|
child: Text('连接设备'),
|
|
);
|
|
} else {
|
|
return SizedBox();
|
|
}
|
|
}),
|
|
|
|
// 电池状态
|
|
SizedBox(height: 12.h),
|
|
Obx(() => controller.isConnected
|
|
? Row(
|
|
children: [
|
|
// 左耳机
|
|
Expanded(
|
|
child: _buildBatteryItem('左耳机', controller.leftEarbudBattery, Icons.headset),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
// 右耳机
|
|
Expanded(
|
|
child: _buildBatteryItem('右耳机', controller.rightEarbudBattery, Icons.headset),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
// 充电盒
|
|
Expanded(
|
|
child: _buildBatteryItem('充电盒', controller.caseBattery, Icons.cases_outlined),
|
|
),
|
|
],
|
|
)
|
|
: const SizedBox()),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 电池状态项
|
|
Widget _buildBatteryItem(String label, int percentage, IconData icon) {
|
|
Color batteryColor;
|
|
IconData batteryIcon;
|
|
|
|
// 根据电量设置颜色和图标
|
|
if (percentage >= 70) {
|
|
batteryColor = Colors.green;
|
|
batteryIcon = Icons.battery_full;
|
|
} else if (percentage >= 30) {
|
|
batteryColor = Colors.amber;
|
|
batteryIcon = Icons.battery_5_bar;
|
|
} else {
|
|
batteryColor = Colors.red;
|
|
batteryIcon = Icons.battery_1_bar;
|
|
}
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[100],
|
|
borderRadius: BorderRadius.circular(12.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
blurRadius: 4,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
padding: EdgeInsets.all(12.w),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(icon, size: 24.sp, color: Colors.grey[700]),
|
|
SizedBox(height: 8.h),
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: Colors.grey[500],
|
|
),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(batteryIcon, size: 14.sp, color: batteryColor),
|
|
SizedBox(width: 4.w),
|
|
Text(
|
|
'$percentage%',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// AI功能卡片
|
|
Widget _buildAIFunctionsCard() {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Colors.blue.shade100,
|
|
Colors.purple.shade100,
|
|
],
|
|
),
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
padding: EdgeInsets.all(16.w),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'AI助手',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.grey[800],
|
|
),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Text(
|
|
'探索DeepVoice的智能功能',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: Colors.grey[600],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
ElevatedButton(
|
|
onPressed: controller.exploreAIFeatures,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue[600],
|
|
foregroundColor: Colors.white,
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(24.r),
|
|
),
|
|
elevation: 2,
|
|
),
|
|
child: Text(
|
|
'探索',
|
|
style: TextStyle(
|
|
fontSize: 14.sp,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 固件更新卡片
|
|
Widget _buildFirmwareUpdateCard() {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[100],
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
padding: EdgeInsets.all(16.w),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 40.w,
|
|
height: 40.w,
|
|
decoration: BoxDecoration(
|
|
color: Colors.amber[100],
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(
|
|
Icons.download,
|
|
size: 20.sp,
|
|
color: Colors.amber[600],
|
|
),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'固件更新',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.grey[800],
|
|
),
|
|
),
|
|
Text(
|
|
'${controller.firmwareVersion}可用',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: Colors.grey[500],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
ElevatedButton(
|
|
onPressed: controller.updateFirmware,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.grey[200],
|
|
foregroundColor: Colors.grey[700],
|
|
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(24.r),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
child: Text(
|
|
'更新',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 快速功能访问
|
|
Widget _buildQuickFunctions() {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
_buildQuickFunctionItem('降噪', Icons.volume_off, Colors.blue[600]!, Colors.blue[100]!, controller.toggleNoiseReduction),
|
|
_buildQuickFunctionItem('音效', Icons.music_note, Colors.purple[600]!, Colors.purple[100]!, controller.openSoundEffects),
|
|
_buildQuickFunctionItem('环境音', Icons.eco, Colors.green[600]!, Colors.green[100]!, controller.toggleAmbientSound),
|
|
_buildQuickFunctionItem('收藏', Icons.favorite, Colors.red[600]!, Colors.red[100]!, controller.openFavorites),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 快速功能项
|
|
Widget _buildQuickFunctionItem(String label, IconData icon, Color iconColor, Color bgColor, VoidCallback onTap) {
|
|
return Column(
|
|
children: [
|
|
Container(
|
|
width: 48.w,
|
|
height: 48.w,
|
|
decoration: BoxDecoration(
|
|
color: bgColor,
|
|
shape: BoxShape.circle,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.2),
|
|
blurRadius: 4,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: IconButton(
|
|
icon: Icon(icon, color: iconColor),
|
|
onPressed: onTap,
|
|
),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|