Browse Source

修改agent输入部件高度抖动问题

weicu
tanlongsheng 1 year ago
parent
commit
4e7b007f2e
  1. 108
      lib/modules/agent/views/agent_view.dart

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

@ -339,14 +339,12 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 图片预览区域 - 仅在图片输入模式下显示
Obx(() {
if (controller.isImageInputActive.value &&
controller.selectedImagePath.value != null) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// 图片预览和关闭按钮
Stack(
@ -421,9 +419,7 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
// 输入控件区域 - 包含输入行和展开的选项
Column(
children: [
// 输入控件行 - 使用IntrinsicHeight确保按钮与输入框底部对齐
IntrinsicHeight(
child: Row(
Row(
crossAxisAlignment:
CrossAxisAlignment.end, // 所有元素底部对齐
children: [
@ -438,6 +434,7 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
child: Container(
width: 44.w,
height: 44.w,
margin: EdgeInsets.symmetric(vertical: 2.w),
decoration: BoxDecoration(
color: isDarkMode
? Colors.grey[800]
@ -473,8 +470,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
overlayBuilder: (params) {
return IntroOverlayBuilder.aiBuilder(
params,
controller.noviceGuideService
.aiStepsList[
controller
.noviceGuideService.aiStepsList[
controller.noviceGuideService
.aiStep]['start'],
buttonText: '确定输入',
@ -482,8 +479,7 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
controller.textController.text =
controller.noviceGuideService
.aiStepsList[
controller
.noviceGuideService
controller.noviceGuideService
.aiStep]['input'];
},
);
@ -492,16 +488,18 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
controller.noviceGuideService
.startAIGuide();
},
builder: (BuildContext context,
GlobalKey key) =>
builder:
(BuildContext context, GlobalKey key) =>
Container(
key: key,
constraints: BoxConstraints(
minHeight: 44.h,
maxHeight: 120.h,
minHeight: 48.w,
),
padding: EdgeInsets.symmetric(
horizontal: 16.w),
horizontal: 16.w,
vertical: 5.w,
),
alignment: Alignment.center,
decoration: BoxDecoration(
color: isDarkMode
? Colors.grey[800]
@ -515,36 +513,26 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
width: 1.w,
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment
.end, // 对齐到底部,实现向上扩展
children: [
Expanded(
child: Obx(() {
// 图片模式下使用更高的输入框
final isImageActive = controller
.isImageInputActive.value;
final isImageActive =
controller.isImageInputActive.value;
return TextField(
controller:
controller.textController,
controller: controller.textController,
maxLines: isImageActive
? 3
: 5, // 设置合理的最大行数
minLines:
isImageActive ? 2 : 1,
keyboardType: TextInputType
.multiline, // 启用多行键盘
minLines: isImageActive ? 2 : 1,
keyboardType:
TextInputType.multiline, // 启用多行键盘
textInputAction:
TextInputAction
.newline, // 支持回车换行
TextInputAction.newline, // 支持回车换行
onTap: () {
// 当点击输入框时,如果'+'选项已展开,则收缩
if (controller
.isPlusOptionsExpanded
.value) {
controller
.collapsePlusOptions();
.isPlusOptionsExpanded.value) {
controller.collapsePlusOptions();
}
},
style: TextStyle(
@ -557,16 +545,15 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
hintText: isImageActive
? 'addQuestionAboutImage'
.tr // 添加对图片的问题或描述...
: 'inputMessage'
.tr, // 输入消息...
: 'inputMessage'.tr, // 输入消息...
hintStyle: TextStyle(
color: Colors.grey[500],
fontSize: 15.sp,
),
filled: false,
isDense: true,
border: InputBorder.none,
focusedBorder:
OutlineInputBorder(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: isDarkMode
? Colors.grey[800]!
@ -574,21 +561,13 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
width: 1.w,
),
),
contentPadding:
EdgeInsets.symmetric(
vertical:
isImageActive
? 12.h
: 8.h),
contentPadding: EdgeInsets.zero,
),
onSubmitted: (_) =>
controller.sendMessage(),
);
}),
),
],
),
),
);
} else {
Timer? _holdTimer; // 增加延迟触发的计时器
@ -640,7 +619,7 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
controller.isListening.value;
return Container(
height: 52.h,
height: 48.w,
padding: EdgeInsets.symmetric(
horizontal: 16.w),
decoration: BoxDecoration(
@ -660,9 +639,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
? Colors.grey[800]!
: Colors.grey
.withOpacity(0.1)),
width: isPushToTalkActive
? 2.w
: 1.w,
width:
isPushToTalkActive ? 2.w : 1.w,
),
),
child: Row(
@ -703,11 +681,9 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
fontSize: 14,
fontWeight:
FontWeight.w500,
color:
isPushToTalkActive
color: isPushToTalkActive
? Colors.blue
: Colors
.grey[600],
: Colors.grey[600],
),
),
],
@ -733,8 +709,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
onHighlightWidgetTap: () async {
await controller
.noviceGuideService.aiStepsList[
controller.noviceGuideService
.aiStep]['method']();
controller.noviceGuideService.aiStep]
['method']();
widgetParams!.onNext!();
controller.sendMessage();
},
@ -755,21 +731,19 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
controller.hasTextInput.value;
final hasImage =
controller.isImageInputActive.value;
final shouldShowSend =
hasText || hasImage;
final shouldShowExpand = controller
.shouldShowExpandButton.value;
final shouldShowSend = hasText || hasImage;
final shouldShowExpand =
controller.shouldShowExpandButton.value;
if (shouldShowSend) {
// 显示发送按钮(可能还有展开按钮)
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// 展开按钮(在发送按钮上方)
if (shouldShowExpand && hasText)
Padding(
padding: EdgeInsets.only(
bottom: 40.h),
padding:
EdgeInsets.only(bottom: 40.h),
child: GestureDetector(
onTap: () {
// 打开底部弹出编辑模式
@ -816,11 +790,12 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
child: Container(
width: 44.w,
height: 44.w,
margin: EdgeInsets.symmetric(
vertical: 2.w),
decoration: BoxDecoration(
color: primaryColor,
borderRadius:
BorderRadius.circular(
22.w),
BorderRadius.circular(22.w),
),
child: Icon(
Icons.send,
@ -843,6 +818,8 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
child: Container(
width: 44.w,
height: 44.w,
margin: EdgeInsets.symmetric(
vertical: 2.w),
decoration: BoxDecoration(
color: isDarkMode
? Colors.grey[800]
@ -869,7 +846,6 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
}),
],
),
),
// 展开的'+'选择选项
Obx(() {

Loading…
Cancel
Save