Browse Source

优化按住说话的输入控件布局

weicu
lxm 1 year ago
parent
commit
ff8826841c
  1. 138
      lib/modules/agent/views/agent_view.dart

138
lib/modules/agent/views/agent_view.dart

@ -197,8 +197,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
controller: controller.scrollController,
shrinkWrap: true,
reverse: true,
padding:
const EdgeInsets.symmetric(vertical: 16, horizontal: 16),
padding: const EdgeInsets.symmetric(
vertical: 16, horizontal: 16),
itemCount: controller.messages.length,
itemBuilder: (context, index) {
final message = controller
@ -206,7 +206,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: GestureDetector(
onLongPressStart: (LongPressStartDetails details) {
onLongPressStart:
(LongPressStartDetails details) {
messageActionController.onLongPressMessage(
context, isDarkMode, details, message);
},
@ -228,7 +229,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
// 输入区域
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: backgroundColor,
boxShadow: [
@ -304,13 +306,15 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
_buildPromptChip(
context: context,
label: '抽取图像文字'.tr,
onTap: () => controller.extractTextFromImage(),
onTap: () =>
controller.extractTextFromImage(),
),
const SizedBox(width: 8),
_buildPromptChip(
context: context,
label: '翻译图像文字'.tr,
onTap: () => controller.translateImageText(),
onTap: () =>
controller.translateImageText(),
),
],
),
@ -329,11 +333,13 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
// 输入控件行 - 使用IntrinsicHeight确保按钮与输入框底部对齐
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.end, // 所有元素底部对齐
crossAxisAlignment:
CrossAxisAlignment.end, // 所有元素底部对齐
children: [
// 键盘/语音切换按钮
Obx(() {
final isTextMode = controller.isTextInputMode.value;
final isTextMode =
controller.isTextInputMode.value;
return GestureDetector(
onTap: () {
controller.toggleInputMode();
@ -348,7 +354,9 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
borderRadius: BorderRadius.circular(22),
),
child: Icon(
isTextMode ? Icons.mic_none : Icons.keyboard,
isTextMode
? Icons.mic_none
: Icons.keyboard,
color: isDarkMode
? Colors.grey[300]
: Colors.grey[700],
@ -389,8 +397,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
),
),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.end, // 对齐到底部,实现向上扩展
crossAxisAlignment: CrossAxisAlignment
.end, // 对齐到底部,实现向上扩展
children: [
Expanded(
child: Obx(() {
@ -434,7 +442,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
),
filled: false,
border: InputBorder.none,
focusedBorder: OutlineInputBorder(
focusedBorder:
OutlineInputBorder(
borderSide: BorderSide(
color: isDarkMode
? Colors.grey[800]!
@ -458,22 +467,24 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
);
} else {
// 语音输入模式 - 按住说话模式
return GestureDetector(
onLongPressStart: (_) {
return Listener(
onPointerDown: (_) {
// 开始按住说话
controller.startPushToTalk();
},
onLongPressEnd: (_) {
onPointerUp: (_) {
// 结束按住说话
controller.endPushToTalk();
},
onLongPressCancel: () {
// 取消按住说话
controller.endPushToTalk();
},
// onLongPressCancel: () {
// // 取消按住说话
// controller.endPushToTalk();
// },
child: Obx(() {
final isPushToTalkActive = controller.isPushToTalkActive.value;
final isListening = controller.isListening.value;
final isPushToTalkActive =
controller.isPushToTalkActive.value;
final isListening =
controller.isListening.value;
return Container(
height: 50,
@ -481,16 +492,24 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
horizontal: 16),
decoration: BoxDecoration(
color: isPushToTalkActive
? (isDarkMode ? Colors.blue[900] : Colors.blue[100])
: (isDarkMode ? Colors.grey[800] : Colors.grey[200]),
borderRadius: BorderRadius.circular(22),
? (isDarkMode
? Colors.blue[900]
: Colors.blue[100])
: (isDarkMode
? Colors.grey[800]
: Colors.grey[200]),
borderRadius:
BorderRadius.circular(22),
border: Border.all(
color: isPushToTalkActive
? Colors.blue
: (isDarkMode
? Colors.grey[800]!
: Colors.grey.withOpacity(0.1)),
width: isPushToTalkActive ? 2.0 : 1.0,
: Colors.grey
.withOpacity(0.1)),
width: isPushToTalkActive
? 2.0
: 1.0,
),
),
child: Row(
@ -498,18 +517,23 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
// 语音波形图 - 只在按住时显示
if (isPushToTalkActive) ...[
const AgentSoundBarsWidget(),
const Spacer(),
//const Spacer(),
],
// 状态文字和图标
Expanded(
child: Row(
mainAxisAlignment: isPushToTalkActive
? MainAxisAlignment.end
: MainAxisAlignment.center,
mainAxisAlignment:
isPushToTalkActive
? MainAxisAlignment
.center
: MainAxisAlignment
.center,
children: [
Icon(
isPushToTalkActive ? Icons.mic : Icons.mic_none,
isPushToTalkActive
? Icons.mic
: Icons.mic_none,
size: 16,
color: isPushToTalkActive
? Colors.blue
@ -522,10 +546,13 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
: '按住说话',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: isPushToTalkActive
fontWeight:
FontWeight.w500,
color:
isPushToTalkActive
? Colors.blue
: Colors.grey[600],
: Colors
.grey[600],
),
),
],
@ -568,12 +595,14 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
backgroundColor:
Colors.transparent,
builder: (context) =>
const FullScreenEditor(),
).then((_) {
// 弹出页关闭时的回调
controller.closeFullScreenEdit();
controller
.closeFullScreenEdit();
});
},
child: Container(
@ -604,7 +633,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
height: 44,
decoration: BoxDecoration(
color: primaryColor,
borderRadius: BorderRadius.circular(22),
borderRadius:
BorderRadius.circular(22),
),
child: const Icon(
Icons.send,
@ -631,7 +661,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
color: isDarkMode
? Colors.grey[800]
: Colors.grey[200],
borderRadius: BorderRadius.circular(22),
borderRadius:
BorderRadius.circular(22),
),
child: Icon(
isExpanded ? Icons.close : Icons.add,
@ -660,9 +691,11 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
child: isExpanded
? Container(
margin: EdgeInsets.only(top: 8.h),
padding: EdgeInsets.symmetric(horizontal:16.w), // 添加左右边距
padding: EdgeInsets.symmetric(
horizontal: 16.w), // 添加左右边距
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, // 改为均匀分布
mainAxisAlignment: MainAxisAlignment
.spaceEvenly, // 改为均匀分布
children: [
// 相机按钮
_buildPlusOptionButton(
@ -734,12 +767,6 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
);
}
// 构建提示选项芯片
Widget _buildPromptChip({
required BuildContext context,
@ -773,8 +800,6 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
);
}
// 构建"+"号展开选项按钮
Widget _buildPlusOptionButton({
required BuildContext context,
@ -923,7 +948,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
children: [
// 音频可视化圆圈
Obx(() {
final isActive = controller.isListening.value || controller.isSpeaking.value;
final isActive =
controller.isListening.value || controller.isSpeaking.value;
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
width: isActive ? 200 : 160,
@ -982,7 +1008,9 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
children: [
// 静音按钮
Obx(() => _buildPhoneControlButton(
icon: controller.isTtsEnabled.value ? Icons.volume_up : Icons.volume_off,
icon: controller.isTtsEnabled.value
? Icons.volume_up
: Icons.volume_off,
onTap: () => controller.toggleTts(),
isDarkMode: isDarkMode,
isActive: controller.isTtsEnabled.value,
@ -1007,7 +1035,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
color: isActive ? Colors.red : Colors.green,
boxShadow: [
BoxShadow(
color: (isActive ? Colors.red : Colors.green).withOpacity(0.3),
color: (isActive ? Colors.red : Colors.green)
.withOpacity(0.3),
blurRadius: 12,
spreadRadius: 2,
),
@ -1050,7 +1079,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
height: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: backgroundColor ?? (isDarkMode ? Colors.grey[800] : Colors.grey[200]),
color: backgroundColor ??
(isDarkMode ? Colors.grey[800] : Colors.grey[200]),
border: isActive ? Border.all(color: Colors.blue, width: 2) : null,
),
child: Icon(
@ -1064,7 +1094,3 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
);
}
}

Loading…
Cancel
Save