|
|
|
@ -113,6 +113,13 @@ class ChatView extends GetView<ChatController> { |
|
|
|
], |
|
|
|
), |
|
|
|
actions: [ |
|
|
|
IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.phone, |
|
|
|
color: isDarkMode ? Colors.white : Colors.black87, |
|
|
|
), |
|
|
|
onPressed: controller.startVoiceRecognition, |
|
|
|
), |
|
|
|
// TTS开关 |
|
|
|
Obx(() => IconButton( |
|
|
|
icon: Icon( |
|
|
|
@ -389,120 +396,122 @@ class ChatView extends GetView<ChatController> { |
|
|
|
Widget _buildTextInputPanel( |
|
|
|
bool isDarkMode, TextEditingController textController) { |
|
|
|
return Container( |
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), |
|
|
|
height: 48.w, |
|
|
|
margin: EdgeInsets.only(left: 16.w, right: 16.w, top: 10.w, bottom: 20.w), |
|
|
|
clipBehavior: Clip.hardEdge, |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: isDarkMode ? AppColors.cardBackground : Colors.white, |
|
|
|
color: controller.isHoldSpeak.value |
|
|
|
? AppColors.primary |
|
|
|
: isDarkMode |
|
|
|
? AppColors.cardBackground |
|
|
|
: Colors.white, |
|
|
|
borderRadius: BorderRadius.circular(12.w), |
|
|
|
boxShadow: [ |
|
|
|
BoxShadow( |
|
|
|
color: Colors.black.withOpacity(0.05), |
|
|
|
blurRadius: 3, |
|
|
|
offset: Offset(0, -1), |
|
|
|
offset: const Offset(0, -1), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
child: SafeArea( |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
// 语音识别按钮 |
|
|
|
Container( |
|
|
|
width: 40.w, |
|
|
|
height: 40.w, |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: isDarkMode |
|
|
|
? Colors.white.withOpacity(0.1) |
|
|
|
: Colors.grey[100], |
|
|
|
shape: BoxShape.circle, |
|
|
|
), |
|
|
|
child: IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.mic_none, |
|
|
|
color: isDarkMode ? Colors.white : Colors.grey[700], |
|
|
|
size: 20.r, |
|
|
|
), |
|
|
|
padding: EdgeInsets.zero, |
|
|
|
onPressed: controller.startVoiceRecognition, |
|
|
|
), |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
child: Obx( |
|
|
|
() => controller.isTextInput.value |
|
|
|
? Center( |
|
|
|
child: TextField( |
|
|
|
controller: textController, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 15.sp, |
|
|
|
color: isDarkMode ? Colors.white : Colors.black87, |
|
|
|
), |
|
|
|
textInputAction: TextInputAction.send, |
|
|
|
decoration: InputDecoration( |
|
|
|
hintText: 'inputMessage'.tr, // 输入消息... |
|
|
|
hintStyle: TextStyle(color: Colors.grey[500]), |
|
|
|
filled: false, |
|
|
|
border: InputBorder.none, |
|
|
|
focusedBorder: InputBorder.none, |
|
|
|
contentPadding: EdgeInsets.only(left: 10.w), |
|
|
|
), |
|
|
|
onSubmitted: (value) { |
|
|
|
if (value.trim().isNotEmpty) { |
|
|
|
controller.sendMessage(value); |
|
|
|
textController.clear(); |
|
|
|
controller.inputText.value = ''; // 清空输入框 |
|
|
|
} |
|
|
|
}, |
|
|
|
), |
|
|
|
) |
|
|
|
: Listener( |
|
|
|
onPointerDown: (event) { |
|
|
|
controller.talkLongPress(); |
|
|
|
}, |
|
|
|
onPointerUp: (event) { |
|
|
|
controller.talkLongPressUp(); |
|
|
|
}, |
|
|
|
child: Container( |
|
|
|
padding: EdgeInsets.only( |
|
|
|
left: controller.isHoldSpeak.value ? 0 : 46.w), |
|
|
|
color: Colors.transparent, |
|
|
|
child: controller.isHoldSpeak.value |
|
|
|
? Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
children: List.generate(40, (int index) { |
|
|
|
return Container( |
|
|
|
width: 3.w, |
|
|
|
height: 10.w, |
|
|
|
margin: |
|
|
|
EdgeInsets.symmetric(horizontal: 2.w), |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: Colors.white, |
|
|
|
borderRadius: BorderRadius.circular(3.r), |
|
|
|
), |
|
|
|
); |
|
|
|
}), |
|
|
|
) |
|
|
|
: Center( |
|
|
|
child: Text( |
|
|
|
'按住说话', |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
color: isDarkMode |
|
|
|
? Colors.white |
|
|
|
: Colors.black87, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
SizedBox(width: 8.w), |
|
|
|
|
|
|
|
// 输入框 |
|
|
|
Expanded( |
|
|
|
child: TextField( |
|
|
|
controller: textController, |
|
|
|
decoration: InputDecoration( |
|
|
|
hintText: 'inputMessage'.tr, // 输入消息... |
|
|
|
hintStyle: TextStyle( |
|
|
|
color: isDarkMode ? Colors.grey[500] : Colors.grey[500]), |
|
|
|
filled: true, |
|
|
|
fillColor: isDarkMode |
|
|
|
? Colors.white.withOpacity(0.1) |
|
|
|
: Colors.grey[100], |
|
|
|
border: OutlineInputBorder( |
|
|
|
borderRadius: BorderRadius.circular(20.r), |
|
|
|
borderSide: BorderSide.none, |
|
|
|
), |
|
|
|
contentPadding: EdgeInsets.symmetric( |
|
|
|
horizontal: 16.w, |
|
|
|
vertical: 10.h, |
|
|
|
), |
|
|
|
if (!controller.isHoldSpeak.value) |
|
|
|
GestureDetector( |
|
|
|
onTap: () { |
|
|
|
controller.isTextInput.value = !controller.isTextInput.value; |
|
|
|
}, |
|
|
|
child: Container( |
|
|
|
width: 30.w, |
|
|
|
height: 30.w, |
|
|
|
margin: EdgeInsets.all(8.w), |
|
|
|
alignment: Alignment.center, |
|
|
|
decoration: BoxDecoration( |
|
|
|
borderRadius: BorderRadius.circular(30.r), |
|
|
|
border: Border.all( |
|
|
|
color: isDarkMode ? Colors.white : Colors.black87, |
|
|
|
width: 2, |
|
|
|
), |
|
|
|
), |
|
|
|
maxLines: null, |
|
|
|
textInputAction: TextInputAction.newline, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 15.sp, |
|
|
|
color: isDarkMode ? Colors.white : Colors.black87, |
|
|
|
child: Obx( |
|
|
|
() => Icon( |
|
|
|
controller.isTextInput.value ? Icons.mic : Icons.keyboard, |
|
|
|
size: 20.w, |
|
|
|
), |
|
|
|
), |
|
|
|
onChanged: (value) => controller.inputText.value = value, |
|
|
|
onSubmitted: (value) { |
|
|
|
if (value.trim().isNotEmpty) { |
|
|
|
controller.sendMessage(value); |
|
|
|
textController.clear(); |
|
|
|
controller.inputText.value = ''; // 清空输入框 |
|
|
|
} |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
SizedBox(width: 8.w), |
|
|
|
|
|
|
|
// 发送按钮 |
|
|
|
Obx(() { |
|
|
|
final hasText = controller.inputText.value.isNotEmpty; |
|
|
|
return Container( |
|
|
|
width: 40.w, |
|
|
|
height: 40.w, |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: hasText |
|
|
|
? AppColors.primary |
|
|
|
: isDarkMode |
|
|
|
? Colors.white.withOpacity(0.1) |
|
|
|
: Colors.grey[200], |
|
|
|
shape: BoxShape.circle, |
|
|
|
), |
|
|
|
child: IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.send, |
|
|
|
color: hasText |
|
|
|
? Colors.white |
|
|
|
: isDarkMode |
|
|
|
? Colors.white.withOpacity(0.5) |
|
|
|
: Colors.grey[400], |
|
|
|
size: 18.r, |
|
|
|
), |
|
|
|
padding: EdgeInsets.zero, |
|
|
|
onPressed: hasText |
|
|
|
? () { |
|
|
|
controller.sendMessage(controller.inputText.value); |
|
|
|
textController.clear(); |
|
|
|
controller.inputText.value = ''; // 清空输入框 |
|
|
|
} |
|
|
|
: null, |
|
|
|
), |
|
|
|
); |
|
|
|
}), |
|
|
|
], |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
|