Browse Source

聊天文本复制粘贴删除功能处理;

wr_202303
wurong 4 months ago
parent
commit
7d003d968f
  1. 568
      lib/im/chat_details_page.dart
  2. 4
      lib/im/database/hx_database.dart

568
lib/im/chat_details_page.dart

@ -14,7 +14,6 @@ import 'package:huixiang/im/database/message.dart';
import 'package:huixiang/main.dart';
import 'package:huixiang/retrofit/data/im_user.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/qiniu.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:image_pickers/image_pickers.dart';
@ -26,7 +25,6 @@ import '../../community/release_dynamic.dart';
import '../../generated/l10n.dart';
import '../../utils/font_weight.dart';
import '../retrofit/data/base_data.dart';
import '../retrofit/data/upload_result.dart';
import '../retrofit/data/user_info.dart';
import '../utils/flutter_utils.dart';
import '../view_widget/custom_image.dart';
@ -68,7 +66,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
OnChatMsgInstance.instance.onChatMessage;
final ScrollController scrollController = ScrollController();
String tex = "";
int copyIndex = 0;
String selfUserId = "";
ImUser _toUser;
String conversation;
@ -574,7 +571,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
behavior: HitTestBehavior.opaque,
onTap: () {
setState(() {
copyIndex = 0;
if (emojiShowing) {
emojiShowing = !emojiShowing;
}
@ -638,90 +634,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
// SizedBox(
// height: 16.h,
// ),
// if (copyIndex == -1)
// Stack(
// alignment: Alignment.bottomCenter,
// children: [
// Container(
// padding: EdgeInsets.only(bottom: 13.h),
// child: Container(
// width: 180.w,
// decoration: BoxDecoration(
// color: Color(0xFF2A2A2A),
// borderRadius: BorderRadius.circular(6),
// ),
// padding: EdgeInsets.symmetric(
// horizontal: 32.w,
// vertical: 7.5.h,
// ),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// GestureDetector(
// onTap: () {
// setState(() {
// copyIndex = 0;
// this.copy(tex);
// });
// },
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_copy.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// "复制",
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// ),
// ),
// GestureDetector(
// onTap: () {},
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_delete.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// S.of(context).shanchu,
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// ),
// )
// ],
// ),
// ),
// ),
// Image.asset(
// "assets/image/icon_copy_j.webp",
// height: 17,
// width: 17,
// ),
// ],
// ),
/// not self
if (!isSelf && isText)
@ -764,98 +677,113 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
alignment: Alignment.centerLeft,
child:GestureDetector(
onLongPress: () {
final RenderBox renderBox = _buttonKey.currentContext.findRenderObject() as RenderBox;
final buttonPosition = renderBox.localToGlobal(Offset.zero);
final buttonSize = renderBox.size;
RenderBox renderBox = _buttonKey.currentContext.findRenderObject() as RenderBox;
Offset buttonPosition = renderBox.localToGlobal(Offset.zero);
Size buttonSize = renderBox.size;
setState(() {
// showMenu(
// context: context,
// color: Color(0xFF2A2A2A),
// position: RelativeRect.fromLTRB(
// buttonPosition.dx + (buttonSize.width - 152.w) / 2, //
// buttonPosition.dy - 55,
// buttonPosition.dx + buttonSize.width,
// buttonPosition.dy
// ), ///
// items: [
// PopupMenuItem(
// value: 1,
// height: 30.h,
// padding: EdgeInsets.zero,
// child:Container(
// child:Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// GestureDetector(
// behavior: HitTestBehavior.translucent,
// onTap: () {
// setState(() {
// copyIndex = 0;
// this.copy(messages[position].content);
// Navigator.pop(context);
// });
// },
// child:Padding(
// padding:EdgeInsets.only(left: 28.w,right:25.w),
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_copy.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// "复制",
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// ),
// ),
// ),
// GestureDetector(
// behavior: HitTestBehavior.translucent,
// onTap: () {},
// child: Padding(
// padding:EdgeInsets.only(right: 28.w,left:25.w),
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_delete.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// S.of(context).shanchu,
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// )),
// )
// ],
// ),
// ),
// ),
// ],
// );
});
showMenu(
context: context,
//
elevation: 0,
color: Colors.transparent,
position: RelativeRect.fromLTRB(
buttonPosition.dx + (buttonSize.width - 180.w) / 2, //
buttonPosition.dy - 68,
buttonPosition.dx + buttonSize.width,
buttonPosition.dy
), ///
items: [
PopupMenuItem(
value: 1,
padding: EdgeInsets.zero,
child:Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
padding: EdgeInsets.only(bottom: 13.h),
child: Container(
width: 180.w,
decoration: BoxDecoration(
color: Color(0xFF2A2A2A),
borderRadius: BorderRadius.circular(6),
),
padding:
EdgeInsets.symmetric(horizontal: 32.w, vertical: 7.5.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
setState(() {
this.copy(messages[position].content);
Navigator.pop(context);
});
},
child: Column(
children: [
Image.asset(
"assets/image/icon_chat_copy.webp",
height: 16,
width: 16,
),
SizedBox(
height: 2.h,
),
Text(
"复制",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
],
),
),
GestureDetector(
onTap: () async{
await hxDatabase.deleteByMsgId(messages[position].id.toString());
messages.removeAt(position);
Navigator.pop(context);
},
child: Column(
children: [
Image.asset(
"assets/image/icon_chat_delete.webp",
height: 16,
width: 16,
),
SizedBox(
height: 2.h,
),
Text(
S.of(context).shanchu,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
],
),
)
],
),
),
),
Image.asset(
"assets/image/icon_copy_j.webp",
height: 17,
width: 17,
),
],
),
),
],
);
},
child: Container(
decoration: BoxDecoration(
@ -893,89 +821,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
),
),
// if (copyIndex == 1)
// Stack(
// alignment: Alignment.bottomCenter,
// children: [
// Container(
// padding: EdgeInsets.only(bottom: 13.h),
// child: Container(
// width: 180.w,
// decoration: BoxDecoration(
// color: Color(0xFF2A2A2A),
// borderRadius: BorderRadius.circular(6),
// ),
// padding:
// EdgeInsets.symmetric(horizontal: 32.w, vertical: 7.5.h),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// GestureDetector(
// onTap: () {
// setState(() {
// copyIndex = 0;
// this.copy(tex);
// });
// },
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_copy.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// "复制",
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// ),
// ),
// GestureDetector(
// onTap: () {},
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_delete.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// S.of(context).shanchu,
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// ),
// )
// ],
// ),
// ),
// ),
// Image.asset(
// "assets/image/icon_copy_j.webp",
// height: 17,
// width: 17,
// ),
// ],
// ),
/// self
if (isSelf && isText)
SizedBox(
@ -1014,100 +859,115 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
Expanded(
child: Container(
alignment: Alignment.centerRight,
child: GestureDetector(
child: InkWell(
onLongPress: () {
final RenderBox renderBox = _buttonKey.currentContext.findRenderObject() as RenderBox;
final buttonPosition = renderBox.localToGlobal(Offset.zero);
final buttonSize = renderBox.size;
RenderBox renderBox = _buttonKey.currentContext.findRenderObject() as RenderBox;
Offset buttonPosition = renderBox.localToGlobal(Offset.zero);
Size buttonSize = renderBox.size;
setState(() {
// showMenu(
// context: context,
// color: Color(0xFF2A2A2A),
// position: RelativeRect.fromLTRB(
// buttonPosition.dx + (buttonSize.width - 152.w) / 2, //
// buttonPosition.dy - 55,
// buttonPosition.dx + buttonSize.width,
// buttonPosition.dy
// ), ///
// items: [
// PopupMenuItem(
// value: 1,
// height: 30.h,
// padding: EdgeInsets.zero,
// child:Container(
// child:Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// GestureDetector(
// behavior: HitTestBehavior.translucent,
// onTap: () {
// setState(() {
// copyIndex = 0;
// this.copy(messages[position].content);
// Navigator.pop(context);
// });
// },
// child:Padding(
// padding:EdgeInsets.only(left: 28.w,right:25.w),
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_copy.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// "复制",
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// ),
// ),
// ),
// GestureDetector(
// behavior: HitTestBehavior.translucent,
// onTap: () {},
// child: Padding(
// padding:EdgeInsets.only(right: 28.w,left:25.w),
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_delete.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// S.of(context).shanchu,
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// )),
// )
// ],
// ),
// ),
// ),
// ],
// );
});
showMenu(
context: context,
//
elevation: 0,
color: Colors.transparent,
position: RelativeRect.fromLTRB(
buttonPosition.dx + (buttonSize.width - 180.w) / 2, //
buttonPosition.dy - 68,
buttonPosition.dx + buttonSize.width,
buttonPosition.dy
), ///
items: [
PopupMenuItem(
value: 1,
padding: EdgeInsets.zero,
child:Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
padding: EdgeInsets.only(bottom: 13.h),
child: Container(
width: 180.w,
decoration: BoxDecoration(
color: Color(0xFF2A2A2A),
borderRadius: BorderRadius.circular(6),
),
padding:
EdgeInsets.symmetric(horizontal: 32.w, vertical: 7.5.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
setState(() {
this.copy(messages[position].content);
Navigator.pop(context);
});
},
child: Column(
children: [
Image.asset(
"assets/image/icon_chat_copy.webp",
height: 16,
width: 16,
),
SizedBox(
height: 2.h,
),
Text(
"复制",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
],
),
),
GestureDetector(
onTap: () async{
await hxDatabase.deleteByMsgId(messages[position].id.toString());
messages.removeAt(position);
Navigator.pop(context);
},
child: Column(
children: [
Image.asset(
"assets/image/icon_chat_delete.webp",
height: 16,
width: 16,
),
SizedBox(
height: 2.h,
),
Text(
S.of(context).shanchu,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
],
),
)
],
),
),
),
Image.asset(
"assets/image/icon_copy_j.webp",
height: 17,
width: 17,
),
],
),
),
],
);
},
child: Container(
decoration: BoxDecoration(

4
lib/im/database/hx_database.dart

@ -131,6 +131,10 @@ class HxDatabase {
return db.delete("Message",where: "conversationId = ?", whereArgs: [conversationId]);
}
Future<int> deleteByMsgId(String id) async {
return db.delete("Message",where: "id = ?", whereArgs: [id]);
}
Future<int> deleteAll() async {
return db.delete("Message");
}

Loading…
Cancel
Save