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

4
lib/im/database/hx_database.dart

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

Loading…
Cancel
Save