Browse Source

feat(chat): 添加聊天输入栏更多选项功能-展开 新增更多选项视图,支持图片和相机功能

- 实现点击更多按钮切换选项面板显示状态- 添加图片和相机图标资源引用
-优化键盘收起逻辑,提升用户体验- 使用动画效果增强更多选项面板展开收起体验
ios
Jolie 4 months ago
parent
commit
a77db6d5d9
4 changed files with 150 additions and 59 deletions
  1. BIN
      assets/images/camera.png
  2. BIN
      assets/images/photo.png
  3. 2
      lib/generated/assets.dart
  4. 207
      lib/widget/message/chat_input_bar.dart

BIN
assets/images/camera.png

Before After
Width: 138  |  Height: 138  |  Size: 2.3 KiB

BIN
assets/images/photo.png

Before After
Width: 138  |  Height: 138  |  Size: 2.2 KiB

2
lib/generated/assets.dart

@ -10,6 +10,7 @@ class Assets {
static const String imagesBgEditAvatars = 'assets/images/bg_edit_avatars.png'; static const String imagesBgEditAvatars = 'assets/images/bg_edit_avatars.png';
static const String imagesBgInformation = 'assets/images/bg_information.png'; static const String imagesBgInformation = 'assets/images/bg_information.png';
static const String imagesBtnBgIcon = 'assets/images/btn_bg_icon.png'; static const String imagesBtnBgIcon = 'assets/images/btn_bg_icon.png';
static const String imagesCamera = 'assets/images/camera.png';
static const String imagesDiscoverNol = 'assets/images/discover_nol.png'; static const String imagesDiscoverNol = 'assets/images/discover_nol.png';
static const String imagesDiscoverPre = 'assets/images/discover_pre.png'; static const String imagesDiscoverPre = 'assets/images/discover_pre.png';
static const String imagesEditAvatarsIcon = 'assets/images/edit_avatars_icon.png'; static const String imagesEditAvatarsIcon = 'assets/images/edit_avatars_icon.png';
@ -31,6 +32,7 @@ class Assets {
static const String imagesMore = 'assets/images/more.png'; static const String imagesMore = 'assets/images/more.png';
static const String imagesMoreIcon = 'assets/images/more_icon.png'; static const String imagesMoreIcon = 'assets/images/more_icon.png';
static const String imagesOnlineIcon = 'assets/images/online_icon.png'; static const String imagesOnlineIcon = 'assets/images/online_icon.png';
static const String imagesPhoto = 'assets/images/photo.png';
static const String imagesPlayIcon = 'assets/images/play_icon.png'; static const String imagesPlayIcon = 'assets/images/play_icon.png';
static const String imagesSearch = 'assets/images/search.png'; static const String imagesSearch = 'assets/images/search.png';
static const String imagesSendMessageIcon = 'assets/images/send_message_icon.png'; static const String imagesSendMessageIcon = 'assets/images/send_message_icon.png';

207
lib/widget/message/chat_input_bar.dart

@ -16,6 +16,7 @@ class ChatInputBar extends StatefulWidget {
class _ChatInputBarState extends State<ChatInputBar> { class _ChatInputBarState extends State<ChatInputBar> {
final TextEditingController _textController = TextEditingController(); final TextEditingController _textController = TextEditingController();
bool _isMoreOptionsVisible = false;
void _handleSendMessage() { void _handleSendMessage() {
if (_textController.text.isNotEmpty) { if (_textController.text.isNotEmpty) {
@ -28,73 +29,161 @@ class _ChatInputBarState extends State<ChatInputBar> {
} }
} }
//
void _toggleMoreOptions() {
setState(() {
_isMoreOptionsVisible = !_isMoreOptionsVisible;
//
FocusManager.instance.primaryFocus?.unfocus();
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 16.w),
color: Colors.white,
child: Column(
children: [
SizedBox(height: 10.h),
Row(
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 16.w),
color: Colors.white,
child: Column(
children: [ children: [
Expanded(
child: Container(
height: 40.h,
decoration: BoxDecoration(
color: Color(0xffF5F5F5),
borderRadius: BorderRadius.circular(5.h),
),
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: TextField(
controller: _textController,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "请输入聊天内容~",
hintStyle: TextStyle(fontSize: 14.sp, color: Colors.grey),
SizedBox(height: 10.h),
Row(
children: [
Expanded(
child: Container(
height: 40.h,
decoration: BoxDecoration(
color: Color(0xffF5F5F5),
borderRadius: BorderRadius.circular(5.h),
),
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: TextField(
controller: _textController,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "请输入聊天内容~",
hintStyle: TextStyle(fontSize: 14.sp, color: Colors.grey),
),
style: TextStyle(fontSize: 14.sp, color: Colors.black),
),
), ),
style: TextStyle(fontSize: 14.sp, color: Colors.black),
), ),
),
SizedBox(width: 12.w),
//
Container(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(5.h),
),
child: Text(
"发送",
style: TextStyle(
fontSize: 14.sp,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
).onTap(_handleSendMessage),
],
),
SizedBox(height: 12.h),
//
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
//
Image.asset(Assets.imagesAudio, width: 24.w, height: 24.w),
//
Image.asset(Assets.imagesVideo, width: 24.w, height: 24.w),
//
Image.asset(Assets.imagesGift, width: 24.w, height: 24.w),
//
Image.asset(Assets.imagesEmoji, width: 24.w, height: 24.w),
//
Image.asset(Assets.imagesAdd, width: 24.w, height: 24.w).onTap(_toggleMoreOptions),
],
), ),
SizedBox(width: 12.w),
//
Container(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(5.h),
),
child: Text(
"发送",
style: TextStyle(
fontSize: 14.sp,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
).onTap(_handleSendMessage),
],
),
SizedBox(height: 12.h),
//
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
//
Image.asset(Assets.imagesAudio, width: 24.w, height: 24.w),
//
Image.asset(Assets.imagesVideo, width: 24.w, height: 24.w),
//
Image.asset(Assets.imagesGift, width: 24.w, height: 24.w),
//
Image.asset(Assets.imagesEmoji, width: 24.w, height: 24.w),
//
Image.asset(Assets.imagesAdd, width: 24.w, height: 24.w),
], ],
), ),
],
),
),
//
_buildMoreOptionsView(),
],
);
}
//
Widget _buildMoreOptionsView() {
return AnimatedContainer(
duration: Duration(milliseconds: 300),
height: _isMoreOptionsVisible ? 180.h : 0,
color: Colors.white,
child: _isMoreOptionsVisible
? Container(
padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 20.h),
child: Column(
children: [
SizedBox(height: 10.h),
//
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
//
Column(
children: [
Container(
width: 60.w,
height: 60.w,
decoration: BoxDecoration(
color: Color(0xffF0F5FF),
borderRadius: BorderRadius.circular(8.w),
),
padding: EdgeInsets.all(10.w),
child: Image.asset(Assets.imagesPhoto, width: 40.w, height: 40.w),
),
SizedBox(height: 8.h),
Text(
"图片",
style: TextStyle(
fontSize: 12.sp,
color: Colors.black,
),
),
],
),
SizedBox(width: 40.w),
//
Column(
children: [
Container(
width: 60.w,
height: 60.w,
decoration: BoxDecoration(
color: Color(0xffF0F5FF),
borderRadius: BorderRadius.circular(8.w),
),
padding: EdgeInsets.all(10.w),
child: Image.asset(Assets.imagesCamera, width: 40.w, height: 40.w),
),
SizedBox(height: 8.h),
Text(
"相机",
style: TextStyle(
fontSize: 12.sp,
color: Colors.black,
),
),
],
),
],
),
],
),
)
: null,
); );
} }
} }
Loading…
Cancel
Save