Browse Source

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

wr_202303
wurong 4 months ago
parent
commit
92064b15b7
  1. 134
      lib/im/chat_details_page.dart
  2. 4
      lib/im/chat_friend_group.dart
  3. 3
      lib/im/chat_setting.dart
  4. 2
      lib/im/contact_share.dart
  5. 1
      lib/im/im_search.dart

134
lib/im/chat_details_page.dart

@ -138,7 +138,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
queryUser() async { queryUser() async {
sharedPre = await SharedPreferences.getInstance(); sharedPre = await SharedPreferences.getInstance();
if (apiService == null) if (apiService == null)
apiService = ApiService(Dio(), context: context, token: sharedPre.getString("token")); apiService = ApiService(Dio(),
context: context, token: sharedPre.getString("token"));
if (sharedPre.containsKey('user') && if (sharedPre.containsKey('user') &&
sharedPre.getString('user') != null && sharedPre.getString('user') != null &&
sharedPre.getString('user') != "") { sharedPre.getString('user') != "") {
@ -179,8 +180,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
void jumpToBottom() { void jumpToBottom() {
Future.delayed(const Duration(milliseconds: 100), () { Future.delayed(const Duration(milliseconds: 100), () {
scrollController.position scrollController.position.jumpTo(0);
.jumpTo(0);
}); });
} }
@ -319,7 +319,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
List<String> filePath = mediaPaths.map((e) => e.path).toList(); List<String> filePath = mediaPaths.map((e) => e.path).toList();
Future.forEach(filePath.toSet(), (path) async { Future.forEach(filePath.toSet(), (path) async {
String fileUrl = await qiniu.uploadFile(apiService, path); String fileUrl = await qiniu.uploadFile(apiService, path);
socketClient.sendMessage(_toUser.mid, fileUrl, attach: path, msgType: galleryMode == GalleryMode.image ? 2 : 4).then((value) { socketClient
.sendMessage(_toUser.mid, fileUrl,
attach: path, msgType: galleryMode == GalleryMode.image ? 2 : 4)
.then((value) {
Message message = value; Message message = value;
messages.insert(0, message); messages.insert(0, message);
chatController.clear(); chatController.clear();
@ -329,7 +332,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
}); });
}); });
}); });
} }
setState(() {}); setState(() {});
} }
@ -370,7 +372,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
}, },
heightRatioWithWidth: 0.82, heightRatioWithWidth: 0.82,
); );
});}else if(await Permission.storage.isGranted){ });
} else if (await Permission.storage.isGranted) {
Media medias = await ImagePickers.openCamera( Media medias = await ImagePickers.openCamera(
cameraMimeType: CameraMimeType.photo, cameraMimeType: CameraMimeType.photo,
cropConfig: CropConfig( cropConfig: CropConfig(
@ -383,7 +386,9 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
if (medias == null) return; if (medias == null) return;
String path = medias.path; String path = medias.path;
String fileUrl = await qiniu.uploadFile(apiService, path); String fileUrl = await qiniu.uploadFile(apiService, path);
socketClient.sendMessage(_toUser.mid, fileUrl, attach: path, msgType: 2).then((value) { socketClient
.sendMessage(_toUser.mid, fileUrl, attach: path, msgType: 2)
.then((value) {
Message message = value; Message message = value;
messages.insert(0, message); messages.insert(0, message);
chatController.clear(); chatController.clear();
@ -423,7 +428,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Padding(padding:EdgeInsets.only(right: 10.w,), Padding(
padding: EdgeInsets.only(
right: 10.w,
),
child: Icon( child: Icon(
Icons.add_photo_alternate_outlined, Icons.add_photo_alternate_outlined,
color: Colors.black, color: Colors.black,
@ -635,7 +643,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
// height: 16.h, // height: 16.h,
// ), // ),
/// not self /// not self
if (!isSelf && isText) if (!isSelf && isText)
SizedBox( SizedBox(
@ -677,8 +684,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: GestureDetector( child: GestureDetector(
onLongPress: () { onLongPress: () {
RenderBox renderBox = _buttonKey.currentContext.findRenderObject() as RenderBox; RenderBox renderBox = _buttonKey.currentContext
Offset buttonPosition = renderBox.localToGlobal(Offset.zero); .findRenderObject() as RenderBox;
Offset buttonPosition =
renderBox.localToGlobal(Offset.zero);
Size buttonSize = renderBox.size; Size buttonSize = renderBox.size;
showMenu( showMenu(
@ -687,11 +696,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
elevation: 0, elevation: 0,
color: Colors.transparent, color: Colors.transparent,
position: RelativeRect.fromLTRB( position: RelativeRect.fromLTRB(
buttonPosition.dx + (buttonSize.width - 180.w) / 2, // buttonPosition.dx +
(buttonSize.width - 180.w) / 2, //
buttonPosition.dy - 68, buttonPosition.dy - 68,
buttonPosition.dx + buttonSize.width, buttonPosition.dx + buttonSize.width,
buttonPosition.dy buttonPosition.dy),
), ///
///
items: [ items: [
PopupMenuItem( PopupMenuItem(
value: 1, value: 1,
@ -705,18 +716,22 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
width: 180.w, width: 180.w,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Color(0xFF2A2A2A), color: Color(0xFF2A2A2A),
borderRadius: BorderRadius.circular(6), borderRadius:
BorderRadius.circular(6),
), ),
padding: padding: EdgeInsets.symmetric(
EdgeInsets.symmetric(horizontal: 32.w, vertical: 7.5.h), horizontal: 32.w, vertical: 7.5.h),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
crossAxisAlignment: CrossAxisAlignment.center, MainAxisAlignment.spaceBetween,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [ children: [
GestureDetector( GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
this.copy(messages[position].content); this.copy(messages[position]
.content);
Navigator.pop(context); Navigator.pop(context);
}); });
}, },
@ -736,7 +751,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 12.sp, fontSize: 12.sp,
fontWeight: MyFontWeight.regular, fontWeight:
MyFontWeight.regular,
), ),
), ),
], ],
@ -744,7 +760,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
), ),
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
await hxDatabase.deleteByMsgId(messages[position].id.toString()); await hxDatabase.deleteByMsgId(
messages[position]
.id
.toString());
messages.removeAt(position); messages.removeAt(position);
Navigator.pop(context); Navigator.pop(context);
}, },
@ -764,7 +783,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 12.sp, fontSize: 12.sp,
fontWeight: MyFontWeight.regular, fontWeight:
MyFontWeight.regular,
), ),
), ),
], ],
@ -861,8 +881,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: InkWell( child: InkWell(
onLongPress: () { onLongPress: () {
RenderBox renderBox = _buttonKey.currentContext.findRenderObject() as RenderBox; RenderBox renderBox = _buttonKey.currentContext
Offset buttonPosition = renderBox.localToGlobal(Offset.zero); .findRenderObject() as RenderBox;
Offset buttonPosition =
renderBox.localToGlobal(Offset.zero);
Size buttonSize = renderBox.size; Size buttonSize = renderBox.size;
showMenu( showMenu(
@ -871,11 +893,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
elevation: 0, elevation: 0,
color: Colors.transparent, color: Colors.transparent,
position: RelativeRect.fromLTRB( position: RelativeRect.fromLTRB(
buttonPosition.dx + (buttonSize.width - 180.w) / 2, // buttonPosition.dx +
(buttonSize.width - 180.w) / 2, //
buttonPosition.dy - 68, buttonPosition.dy - 68,
buttonPosition.dx + buttonSize.width, buttonPosition.dx + buttonSize.width,
buttonPosition.dy buttonPosition.dy),
), ///
///
items: [ items: [
PopupMenuItem( PopupMenuItem(
value: 1, value: 1,
@ -889,18 +913,23 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
width: 180.w, width: 180.w,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Color(0xFF2A2A2A), color: Color(0xFF2A2A2A),
borderRadius: BorderRadius.circular(6), borderRadius:
BorderRadius.circular(6),
), ),
padding: padding: EdgeInsets.symmetric(
EdgeInsets.symmetric(horizontal: 32.w, vertical: 7.5.h), horizontal: 32.w,
vertical: 7.5.h),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
crossAxisAlignment: CrossAxisAlignment.center, MainAxisAlignment.spaceBetween,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [ children: [
GestureDetector( GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
this.copy(messages[position].content); this.copy(messages[position]
.content);
Navigator.pop(context); Navigator.pop(context);
}); });
}, },
@ -916,11 +945,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
), ),
Text( Text(
"复制", "复制",
textAlign: TextAlign.center, textAlign:
TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 12.sp, fontSize: 12.sp,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight
.regular,
), ),
), ),
], ],
@ -928,7 +959,11 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
), ),
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
await hxDatabase.deleteByMsgId(messages[position].id.toString()); await hxDatabase
.deleteByMsgId(
messages[position]
.id
.toString());
messages.removeAt(position); messages.removeAt(position);
Navigator.pop(context); Navigator.pop(context);
}, },
@ -944,11 +979,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
), ),
Text( Text(
S.of(context).shanchu, S.of(context).shanchu,
textAlign: TextAlign.center, textAlign:
TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 12.sp, fontSize: 12.sp,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight
.regular,
), ),
), ),
], ],
@ -1054,7 +1091,9 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
child: FutureBuilder( child: FutureBuilder(
future: fetchImageSize(messages[position]), future: fetchImageSize(messages[position]),
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.waiting || snapshot.hasError) { if (snapshot.connectionState ==
ConnectionState.waiting ||
snapshot.hasError) {
return Image.file( return Image.file(
File(messages[position].attach), File(messages[position].attach),
width: 180.w, width: 180.w,
@ -1092,7 +1131,9 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
child: FutureBuilder( child: FutureBuilder(
future: fetchImageSize(messages[position]), future: fetchImageSize(messages[position]),
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.waiting || snapshot.hasError) { if (snapshot.connectionState ==
ConnectionState.waiting ||
snapshot.hasError) {
return Image.file( return Image.file(
File(messages[position].attach), File(messages[position].attach),
width: 180.w, width: 180.w,
@ -1168,9 +1209,12 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
} }
Completer<Size> completer = Completer(); Completer<Size> completer = Completer();
Image.file(file).image.resolve(ImageConfiguration()) Image.file(file)
.image
.resolve(ImageConfiguration())
.addListener(ImageStreamListener((image, synchronousCall) { .addListener(ImageStreamListener((image, synchronousCall) {
size = Size((image.image.width ?? 0).toDouble(), (image.image.height ?? 0).toDouble()); size = Size((image.image.width ?? 0).toDouble(),
(image.image.height ?? 0).toDouble());
size = resizeImage(size); size = resizeImage(size);
Map<String, double> sizeMap = { Map<String, double> sizeMap = {
"width": size.width, "width": size.width,
@ -1229,7 +1273,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
if (commentText.trim() == "") { if (commentText.trim() == "") {
return; return;
} }
socketClient.sendMessage(_toUser.mid, commentText) socketClient
.sendMessage(_toUser.mid, commentText)
.then((value) { .then((value) {
Message message = value; Message message = value;
messages.insert(0, message); messages.insert(0, message);
@ -1448,5 +1493,4 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
print(tex); print(tex);
Clipboard.setData(ClipboardData(text: tex)); Clipboard.setData(ClipboardData(text: tex));
} }
} }

4
lib/im/chat_friend_group.dart

@ -4,18 +4,14 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../generated/l10n.dart'; import '../../generated/l10n.dart';
import '../../utils/font_weight.dart';
import '../main.dart';
import '../retrofit/data/base_data.dart'; import '../retrofit/data/base_data.dart';
import '../retrofit/data/social_info.dart'; import '../retrofit/data/social_info.dart';
import '../utils/event_type.dart';
import '../view_widget/my_tab.dart'; import '../view_widget/my_tab.dart';
import 'im_view/custom_underline_tabIndicator.dart'; import 'im_view/custom_underline_tabIndicator.dart';
import 'im_view/friend_groip_list.dart'; import 'im_view/friend_groip_list.dart';

3
lib/im/chat_setting.dart

@ -4,13 +4,10 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/im/database/message.dart'; import 'package:huixiang/im/database/message.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../generated/l10n.dart';
import '../../utils/font_weight.dart'; import '../../utils/font_weight.dart';
import '../main.dart'; import '../main.dart';
import '../retrofit/data/im_user.dart'; import '../retrofit/data/im_user.dart';

2
lib/im/contact_share.dart

@ -8,8 +8,6 @@ import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import '../../generated/l10n.dart';
import '../../retrofit/data/base_data.dart';
import '../../utils/font_weight.dart'; import '../../utils/font_weight.dart';
class ContactsShare extends StatefulWidget { class ContactsShare extends StatefulWidget {

1
lib/im/im_search.dart

@ -3,7 +3,6 @@ import 'dart:ui';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';

Loading…
Cancel
Save