From d3d7bff8b6c8521c761cb4ae0258ad07b0f7ed6d Mon Sep 17 00:00:00 2001 From: zsw Date: Sun, 29 Sep 2024 18:31:11 +0800 Subject: [PATCH] convastion list message type show --- lib/im/chat_details_page.dart | 63 ++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/lib/im/chat_details_page.dart b/lib/im/chat_details_page.dart index a8b55de0..a1471727 100644 --- a/lib/im/chat_details_page.dart +++ b/lib/im/chat_details_page.dart @@ -135,15 +135,17 @@ class _ChatDetailsPage extends State } } + SharedPreferences sharedPre; + ///查询个人信息 queryUser() async { - final SharedPreferences value = await SharedPreferences.getInstance(); + sharedPre = await SharedPreferences.getInstance(); if (apiService == null) - apiService = ApiService(Dio(), context: context, token: value.getString("token")); - if (value.containsKey('user') && - value.getString('user') != null && - value.getString('user') != "") { - userInfo = UserInfo.fromJson(jsonDecode(value.getString('user'))); + apiService = ApiService(Dio(), context: context, token: sharedPre.getString("token")); + if (sharedPre.containsKey('user') && + sharedPre.getString('user') != null && + sharedPre.getString('user') != "") { + userInfo = UserInfo.fromJson(jsonDecode(sharedPre.getString('user'))); if (userInfo.phone?.isNotEmpty ?? false) { setState(() {}); return; @@ -382,8 +384,17 @@ class _ChatDetailsPage extends State compressSize: 500, ); if (medias == null) return; - filePath = medias.path; - fileUpload(); + String path = medias.path; + String fileUrl = await qiniu.uploadFile(apiService, path); + socketClient.sendMessage(_toUser.mid, fileUrl, attach: path, msgType: 2).then((value) { + Message message = value; + messages.insert(0, message); + chatController.clear(); + messageShowTime().then((value) { + refreshState(); + jumpToBottom(); + }); + }); }else{ showCameraTipsAlertDialog(context); return false; @@ -393,19 +404,6 @@ class _ChatDetailsPage extends State return false; } } - String filePath; - - ///文件上传 - fileUpload() async { - if (filePath != null && filePath != "" && await File(filePath).exists()) { - BaseData baseData = await apiService - .upload(File(filePath), 123123123, false) - .catchError((onError) {}); - if (baseData != null && baseData.isSuccess) { - UploadResult uploadResult = baseData.data; - } - } - } ///拍照权限说明 showCameraTipsAlertDialog(context) async { @@ -1297,11 +1295,28 @@ class _ChatDetailsPage extends State } Size size = Size.zero; + + if (sharedPre != null) { + String sizeStr = sharedPre.getString(imageLocalPath); + if (sizeStr != null && sizeStr != "") { + Map sizeMap = jsonDecode(sizeStr); + size = Size(sizeMap["width"], sizeMap["height"]); + if (size != Size.zero) { + return size; + } + } + } + Completer completer = Completer(); Image.file(file).image.resolve(ImageConfiguration()) .addListener(ImageStreamListener((image, synchronousCall) { size = Size((image.image.width ?? 0).toDouble(), (image.image.height ?? 0).toDouble()); size = resizeImage(size); + Map sizeMap = { + "width": size.width, + "height": size.height, + }; + sharedPre.setString(imageLocalPath, jsonEncode(sizeMap)); completer.complete(size); })); return completer.future; @@ -1399,9 +1414,9 @@ class _ChatDetailsPage extends State GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - _onMoreTap(); - jumpToBottom(); - // SmartDialog.showToast("暂不支持", alignment: Alignment.center); + // _onMoreTap(); + // jumpToBottom(); + SmartDialog.showToast("暂不支持", alignment: Alignment.center); }, child: Container( padding: EdgeInsets.only(left: 8.w, right: 19.w),