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.
169 lines
5.9 KiB
169 lines
5.9 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import '../controllers/voice_input_controller.dart';
|
|
|
|
class VoiceInputPanel extends GetView<VoiceInputController> {
|
|
const VoiceInputPanel({
|
|
Key? key,
|
|
required this.onRecordingResult,
|
|
required this.onClose,
|
|
required this.onRecognizing,
|
|
}) : super(key: key);
|
|
|
|
final Function(String) onRecordingResult;
|
|
final VoidCallback onClose;
|
|
final Function(String) onRecognizing;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFFFFFFFF), // 纯白色开始
|
|
Color(0xFFE8D5F5), // 更深的紫色结束
|
|
],
|
|
stops: [0.3, 1.0], // 调整颜色分布,让白色占据更多空间
|
|
),
|
|
),
|
|
child: SafeArea(
|
|
child: Container(
|
|
height: 120.h,
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
// 主要内容:麦克风图标、音频波形、关闭按钮
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 20.w),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
// 左侧麦克风图标
|
|
Container(
|
|
width: 60.w,
|
|
height: 60.w,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
shape: BoxShape.circle,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
spreadRadius: 1,
|
|
),
|
|
],
|
|
),
|
|
child: Center(
|
|
child: Icon(
|
|
Icons.mic,
|
|
color: Colors.purple.shade300,
|
|
size: 28.sp,
|
|
),
|
|
),
|
|
),
|
|
|
|
// 中间音频波形
|
|
Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
_buildAudioWaveform(),
|
|
SizedBox(height: 10.h),
|
|
// 文字提示
|
|
Text(
|
|
'你可以开始说话',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.grey.shade700,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
// 右侧关闭按钮
|
|
Container(
|
|
width: 60.w,
|
|
height: 60.w,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
shape: BoxShape.circle,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
spreadRadius: 1,
|
|
),
|
|
],
|
|
),
|
|
child: Center(
|
|
child: IconButton(
|
|
icon: Icon(
|
|
Icons.close,
|
|
color: Colors.grey.shade600,
|
|
size: 28.sp,
|
|
),
|
|
onPressed: onClose,
|
|
padding: EdgeInsets.zero,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// 底部进度条
|
|
Padding(
|
|
padding: EdgeInsets.only(top: 15.h),
|
|
child: Container(
|
|
width: 250.w,
|
|
height: 4.h,
|
|
decoration: BoxDecoration(
|
|
color: Colors.purple.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(2.r),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildAudioWaveform() {
|
|
return Obx(() {
|
|
// 根据控制器状态动态生成波形高度
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: List.generate(
|
|
11,
|
|
(index) {
|
|
// 创建随机高度效果,模拟声波
|
|
double height = controller.isRecording.value
|
|
? (4 + (index % 3) * 3).h // 当正在录音时显示不同高度
|
|
: 4.h; // 默认高度
|
|
|
|
return Container(
|
|
width: 4.w,
|
|
height: height,
|
|
margin: EdgeInsets.symmetric(horizontal: 2.w),
|
|
decoration: BoxDecoration(
|
|
color: controller.isRecording.value
|
|
? Colors.purple.shade300 // 录音时使用紫色
|
|
: Colors.grey.shade400, // 默认使用灰色
|
|
borderRadius: BorderRadius.circular(2.r),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|