|
|
|
@ -1,16 +1,22 @@ |
|
|
|
import 'package:dating_touchme_app/extension/ex_widget.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
|
|
|
|
import '../../generated/assets.dart'; |
|
|
|
import 'more_options_view.dart'; |
|
|
|
import 'voice_input_view.dart'; |
|
|
|
|
|
|
|
class ChatInputBar extends StatefulWidget { |
|
|
|
final ValueChanged<String> onSendMessage; |
|
|
|
final ValueChanged<List<String>>? onImageSelected; |
|
|
|
final Function(String filePath, int seconds)? onVoiceRecorded; |
|
|
|
|
|
|
|
const ChatInputBar({required this.onSendMessage, this.onImageSelected, super.key}); |
|
|
|
const ChatInputBar({ |
|
|
|
required this.onSendMessage, |
|
|
|
this.onImageSelected, |
|
|
|
this.onVoiceRecorded, |
|
|
|
super.key, |
|
|
|
}); |
|
|
|
|
|
|
|
@override |
|
|
|
State<ChatInputBar> createState() => _ChatInputBarState(); |
|
|
|
@ -19,6 +25,7 @@ class ChatInputBar extends StatefulWidget { |
|
|
|
class _ChatInputBarState extends State<ChatInputBar> { |
|
|
|
final TextEditingController _textController = TextEditingController(); |
|
|
|
bool _isMoreOptionsVisible = false; |
|
|
|
bool _isVoiceVisible = false; |
|
|
|
|
|
|
|
void _handleSendMessage() { |
|
|
|
if (_textController.text.isNotEmpty) { |
|
|
|
@ -31,6 +38,9 @@ class _ChatInputBarState extends State<ChatInputBar> { |
|
|
|
void _toggleMoreOptions() { |
|
|
|
setState(() { |
|
|
|
_isMoreOptionsVisible = !_isMoreOptionsVisible; |
|
|
|
if (_isMoreOptionsVisible) { |
|
|
|
_isVoiceVisible = false; |
|
|
|
} |
|
|
|
// 收起键盘 |
|
|
|
FocusManager.instance.primaryFocus?.unfocus(); |
|
|
|
}); |
|
|
|
@ -50,6 +60,16 @@ class _ChatInputBarState extends State<ChatInputBar> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _toggleVoiceOptions() { |
|
|
|
setState(() { |
|
|
|
_isVoiceVisible = !_isVoiceVisible; |
|
|
|
if (_isVoiceVisible) { |
|
|
|
_isMoreOptionsVisible = false; |
|
|
|
} |
|
|
|
FocusManager.instance.primaryFocus?.unfocus(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Column( |
|
|
|
@ -76,7 +96,10 @@ class _ChatInputBarState extends State<ChatInputBar> { |
|
|
|
decoration: InputDecoration( |
|
|
|
border: InputBorder.none, |
|
|
|
hintText: "请输入聊天内容~", |
|
|
|
hintStyle: TextStyle(fontSize: 14.sp, color: Colors.grey), |
|
|
|
hintStyle: TextStyle( |
|
|
|
fontSize: 14.sp, |
|
|
|
color: Colors.grey, |
|
|
|
), |
|
|
|
), |
|
|
|
style: TextStyle(fontSize: 14.sp, color: Colors.black), |
|
|
|
), |
|
|
|
@ -85,7 +108,10 @@ class _ChatInputBarState extends State<ChatInputBar> { |
|
|
|
SizedBox(width: 12.w), |
|
|
|
// 发送按钮 |
|
|
|
Container( |
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), |
|
|
|
padding: EdgeInsets.symmetric( |
|
|
|
horizontal: 16.w, |
|
|
|
vertical: 8.h, |
|
|
|
), |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: Colors.blue, |
|
|
|
borderRadius: BorderRadius.circular(5.h), |
|
|
|
@ -107,7 +133,11 @@ class _ChatInputBarState extends State<ChatInputBar> { |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
|
|
children: [ |
|
|
|
// 语音按钮 |
|
|
|
Image.asset(Assets.imagesAudio, width: 24.w, height: 24.w), |
|
|
|
Image.asset( |
|
|
|
Assets.imagesAudio, |
|
|
|
width: 24.w, |
|
|
|
height: 24.w, |
|
|
|
).onTap(_toggleVoiceOptions), |
|
|
|
// 视频按钮 |
|
|
|
Image.asset(Assets.imagesVideo, width: 24.w, height: 24.w), |
|
|
|
// 礼物按钮 |
|
|
|
@ -115,7 +145,11 @@ class _ChatInputBarState extends State<ChatInputBar> { |
|
|
|
// 表情按钮 |
|
|
|
Image.asset(Assets.imagesEmoji, width: 24.w, height: 24.w), |
|
|
|
// 更多按钮 |
|
|
|
Image.asset(Assets.imagesAdd, width: 24.w, height: 24.w).onTap(_toggleMoreOptions), |
|
|
|
Image.asset( |
|
|
|
Assets.imagesAdd, |
|
|
|
width: 24.w, |
|
|
|
height: 24.w, |
|
|
|
).onTap(_toggleMoreOptions), |
|
|
|
], |
|
|
|
), |
|
|
|
], |
|
|
|
@ -126,10 +160,13 @@ class _ChatInputBarState extends State<ChatInputBar> { |
|
|
|
isVisible: _isMoreOptionsVisible, |
|
|
|
onImageSelected: _handleImageTap, |
|
|
|
onCameraSelected: _handleCameraTap, |
|
|
|
) |
|
|
|
), |
|
|
|
// 语音输入展开视图(与 MoreOptionsView 相同的展开方式) |
|
|
|
VoiceInputView( |
|
|
|
isVisible: _isVoiceVisible, |
|
|
|
onVoiceRecorded: widget.onVoiceRecorded, |
|
|
|
), |
|
|
|
], |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |