Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1546 line
49 KiB

  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'dart:math';
  4. import 'dart:typed_data';
  5. import 'package:cached_network_image/cached_network_image.dart';
  6. import 'package:chat/chat/download_item.dart';
  7. import 'package:chat/chat/file_msg_item.dart';
  8. import 'package:chat/chat/msg_state_widge.dart';
  9. import 'package:chat/chat/place_item.dart';
  10. import 'package:chat/chat/redbag_widget.dart';
  11. import 'package:chat/chat/upload_item.dart';
  12. import 'package:chat/chat/video_view.dart';
  13. import 'package:chat/data/UserData.dart';
  14. import 'package:chat/data/constants.dart';
  15. import 'package:chat/utils/friend_list_mgr.dart';
  16. import 'package:chat/utils/wpop/w_popup_menu.dart';
  17. import 'package:flutter/services.dart';
  18. import 'package:chat/generated/i18n.dart';
  19. import 'package:chat/home/invite_detail_page.dart';
  20. import 'package:chat/models/ChatMsg.dart';
  21. import 'package:chat/models/group_info_model.dart';
  22. import 'package:chat/models/keyboard_provider.dart';
  23. import 'package:chat/proto/chat.pbenum.dart';
  24. import 'package:chat/proto/chat.pbserver.dart';
  25. import 'package:chat/utils/CustomUI.dart';
  26. import 'package:chat/utils/MessageMgr.dart';
  27. import 'package:chat/utils/app_navigator.dart';
  28. import 'package:chat/utils/date_utils.dart';
  29. import 'package:chat/utils/group_member_model.dart';
  30. import 'package:chat/utils/msgHandler.dart';
  31. import 'package:chat/utils/screen.dart';
  32. import 'package:chat/utils/sound_util.dart';
  33. import 'package:chat/utils/upload_util.dart';
  34. import 'package:chat/utils/video_anim.dart';
  35. import 'package:dio/dio.dart';
  36. import 'package:flutter/cupertino.dart';
  37. import 'package:flutter/material.dart';
  38. import 'package:provider/provider.dart';
  39. import 'package:oktoast/oktoast.dart';
  40. import 'package:chat/utils/HttpUtil.dart';
  41. import 'package:share_extend/share_extend.dart';
  42. import 'package:url_launcher/url_launcher.dart';
  43. import '../r.dart';
  44. import '../utils/file_cache_mgr.dart';
  45. import 'full_img_view.dart';
  46. import 'upload_item.dart';
  47. import 'package:chat/models/ref_name_provider.dart';
  48. import 'package:chat/models/money_change.dart';
  49. import 'package:chat/models/voucher_change.dart';
  50. const double ChatRadius = 7.5;
  51. const Color SendMsgBg = Color(0xFFD4F0FF);
  52. const Color SendMsgText = Colors.black;
  53. const double TextHeight = 1.2;
  54. const double PaddingLeft = 9.5;
  55. const Color ReciveBorderColor = Color(0xFFDCDCDC);
  56. const double FontSize = 15;
  57. class GroupChatPageItem extends StatefulWidget {
  58. final MsgModel msg;
  59. final int lastMsgTime;
  60. final GroupMemberModel memberModel;
  61. final Function hideKeyboard;
  62. const GroupChatPageItem(
  63. {Key key,
  64. this.msg,
  65. this.lastMsgTime,
  66. this.hideKeyboard,
  67. this.memberModel})
  68. : assert(msg != null),
  69. super(key: key);
  70. @override
  71. _GroupChatPageItemState createState() => _GroupChatPageItemState();
  72. }
  73. class _GroupChatPageItemState extends State<GroupChatPageItem>
  74. with SingleTickerProviderStateMixin {
  75. int curTextType = 0; //文字、译文切换索引
  76. List<String> textList = [];
  77. String curSoundUrl;
  78. CancelToken _cancelToken = CancelToken();
  79. bool isLongPressed = false;
  80. double maxWidth = Screen.width - 140;
  81. @override
  82. void initState() {
  83. super.initState();
  84. if (widget.msg.from == UserData().basicInfo.userId &&
  85. widget.msg.state == MsgState.None) {
  86. print('重新发送消息');
  87. MsgHandler.sendChatMsg(widget.msg);
  88. }
  89. textList = widget.msg.getTransTextList();
  90. MessageMgr().on('Update Translate Message', updateTranslateMsg);
  91. MessageMgr().on('Cancel Request', _deleteItem);
  92. }
  93. @override
  94. void dispose() {
  95. MessageMgr().off('Cancel Request', _deleteItem);
  96. MessageMgr().off('Update Translate Message', updateTranslateMsg);
  97. super.dispose();
  98. }
  99. _deleteItem(msg) {
  100. if (msg == widget.msg) {
  101. print(widget.msg.state);
  102. if (widget.msg.state == MsgState.Uploading) {
  103. print('取消上传');
  104. UploadUtil().cancelRequests(_cancelToken);
  105. }
  106. }
  107. }
  108. updateTextList() {
  109. textList.clear();
  110. curTextType = 0;
  111. textList = widget.msg.getTransTextList();
  112. }
  113. updateTranslateMsg(msg) {
  114. if (msg.time == widget.msg.time) {
  115. if (mounted) {
  116. updateTextList();
  117. if (!mounted) {
  118. return;
  119. }
  120. setState(() {
  121. print('更新翻译文字');
  122. });
  123. }
  124. }
  125. }
  126. getTodayTime(msgDate, {var sendTime}) {
  127. String showTimeStr;
  128. sendTime = sendTime ?? widget.msg.time;
  129. var today = DateTime.now();
  130. //今天
  131. if (msgDate.year == today.year &&
  132. msgDate.month == today.month &&
  133. msgDate.day == today.day) {
  134. showTimeStr =
  135. DateUtils().getFormartData(timeSamp: sendTime, format: 'HH:mm');
  136. } else {
  137. showTimeStr =
  138. DateUtils().getFormartData(timeSamp: sendTime, format: 'MM/dd HH:mm');
  139. }
  140. return showTimeStr;
  141. }
  142. String getMsgTime() {
  143. String showTimeStr;
  144. var sendTime = widget.msg.time;
  145. var msgDate = DateTime.fromMillisecondsSinceEpoch(sendTime);
  146. if (widget.lastMsgTime == null) {
  147. showTimeStr = getTodayTime(msgDate);
  148. } else {
  149. if (sendTime - widget.lastMsgTime > 3 * 60 * 1000) {
  150. showTimeStr = getTodayTime(msgDate);
  151. }
  152. }
  153. return showTimeStr;
  154. }
  155. @override
  156. Widget build(BuildContext context) {
  157. var showTime = getMsgTime();
  158. return Container(
  159. width: Screen.width,
  160. color: Colors.white.withOpacity(0),
  161. margin: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 8),
  162. child: Column(
  163. children: <Widget>[
  164. showTime == null
  165. ? SizedBox()
  166. : Container(
  167. decoration: BoxDecoration(
  168. color: Color(0xFF2C2F36).withOpacity(0.25),
  169. borderRadius: BorderRadius.all(Radius.circular(9.5))),
  170. padding:
  171. EdgeInsets.only(left: 7, right: 7, top: 3, bottom: 2),
  172. child: Text(showTime,
  173. textScaleFactor: 1.0,
  174. style: TextStyle(fontSize: 10.0, color: Colors.white)),
  175. ),
  176. SizedBox(height: 10),
  177. _msgWidget()
  178. ],
  179. ),
  180. );
  181. }
  182. _msgWidget() {
  183. if (widget.msg.from == 0) {
  184. return _serverNotifyMsg();
  185. } else {
  186. if (widget.msg.from == UserData().basicInfo.userId) {
  187. return _getSentMessageLayout(context);
  188. } else {
  189. return _getReceivedMessageLayout(context);
  190. }
  191. }
  192. }
  193. _serverNotifyMsg() {
  194. var type = widget.msg.msgType;
  195. if (type == ChatType.GroupChatNoticeType.value) {
  196. var res = GroupChatNotice.fromBuffer(widget.msg.msgContent);
  197. var groupInfoModel = Provider.of<GroupInfoModel>(context);
  198. var optId = res.operatuId;
  199. var showStr = MsgHandler.getGroupNoticeMsg(res, groupInfoModel);
  200. return Container(
  201. alignment: Alignment.center,
  202. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  203. child: extendedText(showStr,
  204. color: Constants.GreyTextColor,
  205. fontSize: 12, onSpecialTextTap: (dynamic parameter) {
  206. // print('点击事件 $parameter');
  207. if (parameter.startsWith("\$")) {
  208. // showToast('点击: ${res.operateduId[0]}');
  209. List<GroupMemberModel> list = [];
  210. for (int k = 0; k < res.operateduId.length; k++) {
  211. list.add(GroupMemberModel.fromBaseInfo(res.operateduId[k]));
  212. }
  213. AppNavigator.push(
  214. context,
  215. InviteDetailPage(
  216. originalList: list,
  217. opt: GroupMemberModel.fromBaseInfo(optId),
  218. groupId: groupInfoModel.sessionId,
  219. ));
  220. }
  221. }),
  222. );
  223. }
  224. return Container();
  225. }
  226. _textGif(List<int> msgContent) {
  227. var msg = utf8.decode(msgContent);
  228. return Container(
  229. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  230. child: extendedText(
  231. msg,
  232. selectionEnabled: false,
  233. hideKeyboard: widget.hideKeyboard,
  234. fontSize: FontSize,
  235. color: Colors.black,
  236. ),
  237. );
  238. }
  239. double getQuoteContentWidth(QuoteMsg quoteMsg, String refName,
  240. String showTimeStr, String quoteContent) {
  241. double width;
  242. var timetWidth = CustomUI.getRealTextWidht(showTimeStr, 13);
  243. var nameWidhth = CustomUI.getRealTextWidht(refName, 13);
  244. width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 59;
  245. var contentWidht = _getTextWidth(quoteContent, fontSize: 13);
  246. return min(max(width, contentWidht), maxWidth);
  247. }
  248. Widget getQuoteContent(QuoteMsg quoteMsg, String refName, String showTimeStr,
  249. String quoteContent, bool isSend) {
  250. var strColor;
  251. var bgColor;
  252. if (isSend) {
  253. strColor = const Color(0xFF24343C);
  254. bgColor = const Color(0xFFC4E0F5);
  255. } else {
  256. strColor = const Color(0xFF515151);
  257. bgColor = const Color(0xFFEBEBEC);
  258. }
  259. return Container(
  260. padding: EdgeInsets.only(left: 8, bottom: 8),
  261. margin: EdgeInsets.only(bottom: 5, top: 2),
  262. decoration:
  263. BoxDecoration(color: bgColor, borderRadius: BorderRadius.circular(7)),
  264. child: Column(
  265. crossAxisAlignment: CrossAxisAlignment.start,
  266. children: <Widget>[
  267. Row(children: <Widget>[
  268. Container(
  269. constraints: BoxConstraints(maxWidth: 70),
  270. child: Text(
  271. refName,
  272. style: TextStyle(fontSize: 13, color: strColor),
  273. overflow: TextOverflow.ellipsis,
  274. )),
  275. SizedBox(width: 10),
  276. Text(
  277. showTimeStr,
  278. style: TextStyle(fontSize: 13, color: strColor),
  279. ),
  280. Expanded(child: SizedBox()),
  281. InkWell(
  282. onTap: () {
  283. MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt());
  284. },
  285. child: Container(
  286. alignment: Alignment.center,
  287. height: 27,
  288. padding: EdgeInsets.only(
  289. left: 10,
  290. right: 10,
  291. ),
  292. child: Icon(
  293. IconData(0xe67e, fontFamily: Constants.IconFontFamily),
  294. size: 13,
  295. color: strColor,
  296. )))
  297. ]),
  298. Padding(
  299. padding: EdgeInsets.only(right: 8),
  300. child: Text(
  301. quoteContent,
  302. style: TextStyle(fontSize: 13, color: strColor),
  303. ),
  304. ),
  305. ],
  306. ),
  307. );
  308. }
  309. Map getQuoteItem(MsgModel msgModel) {
  310. QuoteMsg quoteMsg = QuoteMsg.fromBuffer(widget.msg.refMsgContent);
  311. var refName = Provider.of<RefNameProvider>(context)
  312. .getGroupRefName(msgModel.sessionId, quoteMsg.sendUserId);
  313. var msgDate =
  314. DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt());
  315. var showTimeStr =
  316. getTodayTime(msgDate, sendTime: quoteMsg.sendTime.toInt());
  317. var tempIndex = quoteMsg.content.indexOf(':');
  318. var quoteContent = tempIndex == -1
  319. ? quoteMsg.content
  320. : quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2);
  321. return {
  322. "quoteMsg": quoteMsg,
  323. "refName": refName,
  324. "showTimeStr": showTimeStr,
  325. "quoteContent": quoteContent,
  326. };
  327. }
  328. _textMsg(MsgModel msgModel) {
  329. List<Widget> showMsg = [];
  330. var width = 0.0;
  331. var msg = utf8.decode(msgModel.msgContent);
  332. if (msg.contains('[ ')) {
  333. msg = msg.replaceAll('[ ', '[');
  334. }
  335. if (msg.contains(' ]')) {
  336. msg = msg.replaceAll(' ]', ']');
  337. }
  338. bool isUrl = false;
  339. if (textList[curTextType].contains('http')) {
  340. isUrl = true;
  341. }
  342. if (msgModel.refMsgContent != null && msgModel.refMsgContent.length > 0) {
  343. var quoteItem = getQuoteItem(msgModel);
  344. width = getQuoteContentWidth(quoteItem['quoteMsg'], quoteItem['refName'],
  345. quoteItem['showTimeStr'], quoteItem['quoteContent']);
  346. showMsg.add(getQuoteContent(quoteItem['quoteMsg'], quoteItem['refName'],
  347. quoteItem['showTimeStr'], quoteItem['quoteContent'], true));
  348. }
  349. var contentWidth = _getTextWidth(textList[curTextType]);
  350. width = min(max(contentWidth, width),maxWidth);
  351. showMsg.add(Container(
  352. constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
  353. alignment: Alignment.centerLeft,
  354. child: extendedText(
  355. textList[curTextType],
  356. color: isUrl ? Colors.blue : Constants.BlackTextColor,
  357. hideKeyboard: widget.hideKeyboard,
  358. fontSize: FontSize,
  359. )));
  360. return Container(
  361. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  362. width: width + 20,
  363. child: Column(
  364. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  365. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  366. decoration: BoxDecoration(
  367. color: isLongPressed ? Colors.grey[300] : SendMsgBg,
  368. border: Border.all(color: Color(0xFFB9CBD7), width: 0.6),
  369. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  370. );
  371. }
  372. _soundMsg() {
  373. double time = widget.msg.extraInfo / 1000;
  374. if (time > 60) {
  375. time = 60.0;
  376. }
  377. bool isPlaying = false;
  378. var soundPath = widget.msg.localFile;
  379. isPlaying = SoundUtils().isPlaying(soundPath);
  380. var soundWidget = GestureDetector(
  381. child: Container(
  382. width: 120,
  383. child: Row(
  384. mainAxisAlignment: MainAxisAlignment.end,
  385. children: <Widget>[
  386. Container(
  387. alignment: Alignment.center,
  388. padding: EdgeInsets.only(bottom: 2),
  389. margin: EdgeInsets.only(right: 10),
  390. width: 25.5,
  391. height: 25.5,
  392. decoration: BoxDecoration(
  393. border:
  394. Border.all(color: const Color(0xFF1B92C7), width: 0.5),
  395. color: const Color(0xFF04A4FE),
  396. shape: BoxShape.circle),
  397. child: Icon(
  398. IconData(isPlaying ? 0xe652 : 0xe653,
  399. fontFamily: Constants.IconFontFamily),
  400. size: isPlaying ? 15 : 18,
  401. color: Colors.white,
  402. ),
  403. ),
  404. isPlaying
  405. ? Stack(
  406. children: <Widget>[
  407. Container(
  408. height: 18,
  409. width: 19,
  410. ),
  411. Positioned(
  412. bottom: 0,
  413. child: VideoAnim(
  414. begin: 18,
  415. start: 0.444,
  416. end: 4.5,
  417. )),
  418. Positioned(
  419. left: 7,
  420. bottom: 0,
  421. child: VideoAnim(
  422. begin: 4.5,
  423. end: 18,
  424. )),
  425. Positioned(
  426. left: 14,
  427. bottom: 0,
  428. child: VideoAnim(
  429. begin: 18,
  430. end: 4.5,
  431. ))
  432. ],
  433. )
  434. : Stack(
  435. children: <Widget>[
  436. Container(
  437. height: 18,
  438. width: 19,
  439. ),
  440. Positioned(
  441. bottom: 0, child: CustomUI.buildAudioContaniner(12)),
  442. Positioned(
  443. left: 7,
  444. bottom: 0,
  445. child: CustomUI.buildAudioContaniner(4.5)),
  446. Positioned(
  447. left: 14,
  448. bottom: 0,
  449. child: CustomUI.buildAudioContaniner(18))
  450. ],
  451. ),
  452. Expanded(child: SizedBox()),
  453. fixedText(time.toStringAsFixed(0), color: SendMsgText, fontSize: 16)
  454. ],
  455. ),
  456. padding: EdgeInsets.symmetric(horizontal: 15, vertical: 12),
  457. decoration: BoxDecoration(
  458. color: SendMsgBg,
  459. border: Border.all(color: Color(0xFFB9CBD7), width: 0.6),
  460. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  461. ),
  462. onTap: () async {
  463. print('播放状态 : $isPlaying');
  464. print('当前文件$soundPath ');
  465. if (isPlaying) {
  466. SoundUtils().pause();
  467. } else {
  468. SoundUtils().play(soundPath, onPlayed: () {
  469. if (mounted) {
  470. setState(() {});
  471. }
  472. }, complete: () {
  473. if (mounted) {
  474. setState(() {});
  475. }
  476. });
  477. }
  478. },
  479. );
  480. return UploadImgItem(
  481. msg: widget.msg,
  482. child: soundWidget,
  483. isShowProgress: false,
  484. );
  485. }
  486. Size _getImgSize() {
  487. double aspectRatio = widget.msg.extraInfo / 100;
  488. var maxWidth = Screen.width * 0.65;
  489. var maxHeight = Screen.height / 4;
  490. var width, height;
  491. if (maxWidth / maxHeight > aspectRatio) {
  492. height = maxHeight;
  493. width = maxHeight * aspectRatio;
  494. } else {
  495. width = maxWidth;
  496. height = maxWidth / aspectRatio;
  497. }
  498. return Size(width, height);
  499. }
  500. _imgMsg(List<int> imgData) {
  501. var imgSize = _getImgSize();
  502. ImageProvider provider = MemoryImage(widget.msg.localFile == null
  503. ? Uint8List.fromList(imgData)
  504. : File(widget.msg.localFile).readAsBytesSync());
  505. return GestureDetector(
  506. child: ClipRRect(
  507. child: UploadImgItem(
  508. msg: widget.msg,
  509. cancelToken: _cancelToken,
  510. child: Container(
  511. height: imgSize.height,
  512. width: imgSize.width,
  513. child: Image(
  514. fit: BoxFit.contain,
  515. image: provider,
  516. ),
  517. )),
  518. borderRadius: BorderRadius.circular(5),
  519. ),
  520. onTap: () async {
  521. showFullImg(context, widget.msg);
  522. });
  523. }
  524. _videoMsg(BuildContext context, List<int> thumbnail) {
  525. var imgSize = _getImgSize();
  526. return InkWell(
  527. child: ClipRRect(
  528. child: Stack(
  529. alignment: Alignment.center,
  530. children: <Widget>[
  531. UploadImgItem(
  532. msg: widget.msg,
  533. cancelToken: _cancelToken,
  534. child: Container(
  535. width: imgSize.width,
  536. height: imgSize.height,
  537. child: Image(
  538. fit: BoxFit.contain,
  539. image: MemoryImage(Uint8List.fromList(thumbnail)),
  540. ),
  541. ))
  542. ],
  543. ),
  544. borderRadius: BorderRadius.circular(5),
  545. ),
  546. onTap: () {
  547. showVideoPage(context, widget.msg.localFile);
  548. },
  549. );
  550. }
  551. _msgLayout(BuildContext context, MsgModel msg) {
  552. Widget item;
  553. switch (ChatType.valueOf(msg.msgType)) {
  554. case ChatType.TextChatType:
  555. item = _textMsg(msg);
  556. break;
  557. case ChatType.EmoticonType:
  558. item = _textGif(msg.msgContent);
  559. break;
  560. case ChatType.ImageChatType:
  561. item = _imgMsg(msg.msgContent);
  562. break;
  563. case ChatType.ShortVideoChatType:
  564. item = _videoMsg(context, msg.msgContent);
  565. break;
  566. case ChatType.ShortVoiceChatType:
  567. item = _soundMsg();
  568. break;
  569. case ChatType.RedWalletChatType:
  570. item = RedBagItem(
  571. Key(msg.time.toString()), UserData().basicInfo.userId, msg);
  572. break;
  573. case ChatType.PlaceChatType:
  574. item = PlaceItem(isMe: true, placeContent: msg.msgContent);
  575. break;
  576. case ChatType.FileChatType:
  577. item = _fileMsgItem();
  578. break;
  579. default:
  580. }
  581. return wrapItemWithMenu(item);
  582. }
  583. Widget _fileMsgItem() {
  584. return UploadImgItem(
  585. msg: widget.msg,
  586. cancelToken: _cancelToken,
  587. child: Container(
  588. height: 100,
  589. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  590. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  591. decoration: BoxDecoration(
  592. color: isLongPressed ? Colors.grey[300] : SendMsgBg,
  593. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  594. child: FileMsgItem(widget.msg)));
  595. }
  596. Widget wrapItemWithMenu(item) {
  597. List<Function> actionsFunc = [];
  598. List<String> actions = [
  599. I18n.of(context).reply,
  600. I18n.of(context).delete,
  601. ];
  602. actionsFunc.add(() {
  603. print('发送引用的消息');
  604. MessageMgr().emit('Reply Select Message', widget.msg);
  605. });
  606. actionsFunc.add(() {
  607. MessageMgr().emit('Delete Select Message', widget.msg);
  608. });
  609. ///转发
  610. if (widget.msg.msgType == ChatType.TextChatType.value ||
  611. widget.msg.msgType == ChatType.ImageChatType.value ||
  612. widget.msg.msgType == ChatType.ShortVideoChatType.value ||
  613. widget.msg.msgType == ChatType.PlaceChatType.value ||
  614. widget.msg.msgType == ChatType.EmoticonType.value ||
  615. widget.msg.msgType == ChatType.FileChatType.value) {
  616. actions.add(I18n.of(context).forward);
  617. actionsFunc.add(() {
  618. print('转发消息');
  619. if (widget.msg.msgType == ChatType.FileChatType.value &&
  620. widget.msg.localFile == null) {
  621. showToast('请先下载文件');
  622. return;
  623. }
  624. AppNavigator.pushForwardPage(context, widget.msg);
  625. });
  626. }
  627. if (widget.msg.msgType == ChatType.FileChatType.value &&
  628. widget.msg.localFile != null) {
  629. //分享文件
  630. actions.add(I18n.of(context).copy_download_url);
  631. actionsFunc.add(() async {
  632. //如果是文件增加复制下载地址
  633. String path = widget.msg.localFile;
  634. UploadUtil().copyFileUrl(widget.msg, context);
  635. String type = 'file';
  636. if (path.contains('mp4') || path.contains('mp3')) {
  637. type = 'video';
  638. } else if (path.contains('png') ||
  639. path.contains('jpg') ||
  640. path.contains('jpeg') ||
  641. path.contains('JPG') ||
  642. path.contains('PNG')) {
  643. type = 'image';
  644. }
  645. ShareExtend.share(FileCacheMgr.replacePath(path), type);
  646. });
  647. }
  648. if (widget.msg.msgType == ChatType.TextChatType.value) {
  649. actions.insert(0, I18n.of(context).copy);
  650. actionsFunc.insert(0, () {
  651. //复制当前的文字
  652. print('复制文字 ${textList[curTextType]}');
  653. ClipboardData clipboardData =
  654. ClipboardData(text: textList[curTextType]);
  655. Clipboard.setData(clipboardData);
  656. });
  657. }
  658. if (widget.msg.msgType == ChatType.ShortVoiceChatType.value) {
  659. var soundPlayMode =
  660. Provider.of<KeyboardIndexProvider>(context).soundPlayMode;
  661. actions.add(soundPlayMode
  662. ? I18n.of(context).handset_playback
  663. : I18n.of(context).speaker_play);
  664. actionsFunc.add(() {
  665. Provider.of<KeyboardIndexProvider>(context)
  666. .changeSoundPlayMode(!soundPlayMode);
  667. SoundUtils.instance.savePlayModeConfig(soundPlayMode);
  668. });
  669. }
  670. // String date2 = DateTime.fromMillisecondsSinceEpoch(widget.msg.time).toString();
  671. bool isUrl = false;
  672. if (widget.msg.msgType == ChatType.TextChatType.value) {
  673. if (textList[curTextType].contains('http')) {
  674. isUrl = true;
  675. }
  676. }
  677. return WPopupMenu(
  678. child: item,
  679. actions: actions,
  680. onTap: () async {
  681. MessageMgr().emit('Keyboard Hide');
  682. if (isUrl) {
  683. if (await canLaunch(textList[curTextType])) {
  684. launch(textList[curTextType]);
  685. }
  686. }
  687. },
  688. onLongPressStart: () {
  689. isLongPressed = true;
  690. setState(() {});
  691. },
  692. onLongPressEnd: () {
  693. isLongPressed = false;
  694. setState(() {});
  695. },
  696. onValueChanged: (int value) {
  697. print('选择的是$value个菜单');
  698. if (value >= 0 && value < actionsFunc.length) {
  699. actionsFunc[value]();
  700. }
  701. },
  702. );
  703. }
  704. Widget _getSentMessageLayout(BuildContext context) {
  705. bool hasHeadImg = true;
  706. if (UserData().basicInfo.headimgurl == null ||
  707. UserData().basicInfo.headimgurl.length == 0) {
  708. hasHeadImg = false;
  709. }
  710. return Row(
  711. crossAxisAlignment: CrossAxisAlignment.start,
  712. mainAxisAlignment: MainAxisAlignment.end,
  713. children: <Widget>[
  714. MsgStateWidget(widget.msg),
  715. SizedBox(width: 3),
  716. _msgLayout(context, widget.msg),
  717. SizedBox(width: 10),
  718. Column(
  719. crossAxisAlignment: CrossAxisAlignment.end,
  720. children: <Widget>[
  721. ClipRRect(
  722. borderRadius: BorderRadius.circular(8),
  723. child: hasHeadImg
  724. ? CachedNetworkImage(
  725. imageUrl: UserData().basicInfo.headimgurl,
  726. placeholder: (context, url) => Image.asset(
  727. Constants.DefaultHeadImgUrl,
  728. width: 40,
  729. height: 40,
  730. ),
  731. width: 40,
  732. height: 40,
  733. )
  734. : SizedBox(
  735. width: 40,
  736. height: 40,
  737. child: Image.asset(R.assetsImagesDefaultNorAvatar))),
  738. ],
  739. )
  740. ]);
  741. }
  742. _receiveJIF(MsgModel msg) {
  743. var text = utf8.decode(msg.msgContent);
  744. return Container(
  745. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  746. child: extendedText(text,
  747. selectionEnabled: false, hideKeyboard: widget.hideKeyboard));
  748. }
  749. double _getTextWidth(String text, {double fontSize = FontSize}) {
  750. var tp = TextPainter(
  751. text: TextSpan(
  752. style: TextStyle(fontSize: fontSize), text: textList[curTextType]),
  753. textAlign: TextAlign.left,
  754. textDirection: TextDirection.ltr,
  755. textScaleFactor: 1,
  756. );
  757. tp.layout(maxWidth: maxWidth);
  758. if (text.contains('[')) {
  759. if (text.length < 5 && text.startsWith('[') && text.endsWith(']')) {
  760. ///单表情
  761. return 25;
  762. }
  763. int length = text.split('[').length;
  764. if (length > 1) {
  765. ///包含表情
  766. int scale = 6;
  767. if (length > 6) scale = 7;
  768. double width = tp.width + length * scale;
  769. return width > (maxWidth) ? maxWidth : width;
  770. }
  771. }
  772. return tp.width;
  773. ///单文字
  774. }
  775. blueDot(bool isShow) {
  776. return Container(
  777. margin: EdgeInsets.only(right: 5),
  778. decoration: BoxDecoration(
  779. shape: BoxShape.circle,
  780. color: isShow ? Color(0xFFFF7E00) : Color(0xFFCFCFCF),
  781. ),
  782. width: 4,
  783. height: 4,
  784. );
  785. }
  786. _receiveText(MsgModel msg) {
  787. List<Widget> showMsg = [];
  788. double width = 0.0;
  789. if (textList.length > 0) {
  790. bool isUrl = false;
  791. if (textList[curTextType].contains('http')) {
  792. isUrl = true;
  793. }
  794. if (msg.refMsgContent != null && msg.refMsgContent.length > 0) {
  795. var quoteItem = getQuoteItem(msg);
  796. width = getQuoteContentWidth(
  797. quoteItem['quoteMsg'],
  798. quoteItem['refName'],
  799. quoteItem['showTimeStr'],
  800. quoteItem['quoteContent']);
  801. showMsg.add(getQuoteContent(quoteItem['quoteMsg'], quoteItem['refName'],
  802. quoteItem['showTimeStr'], quoteItem['quoteContent'], false));
  803. }
  804. var contentWidth = _getTextWidth(textList[curTextType]);
  805. if (contentWidth > width && contentWidth <= maxWidth) {
  806. width = contentWidth;
  807. }
  808. showMsg.add(Container(
  809. constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
  810. alignment: Alignment.centerLeft,
  811. child: extendedText(
  812. textList[curTextType],
  813. color: isUrl ? Colors.blue : Constants.BlackTextColor,
  814. hideKeyboard: widget.hideKeyboard,
  815. fontSize: FontSize,
  816. )));
  817. }
  818. var minWidth = width + 20;
  819. if (msg.transTag != 0) {
  820. minWidth = 200;
  821. showMsg.add(Padding(
  822. padding: EdgeInsets.symmetric(vertical: 5),
  823. child: Divider(color: Color(0xFFECECEC), height: 1)));
  824. Widget tranWidget = _transProcessWidget(msg.transTag);
  825. showMsg.add(tranWidget);
  826. }
  827. Widget text = Stack(children: <Widget>[
  828. Container(
  829. width: width + 20,
  830. constraints:
  831. BoxConstraints(maxWidth: Screen.width - 120, minWidth: minWidth),
  832. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  833. child: Column(
  834. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  835. decoration: BoxDecoration(
  836. border: Border.all(color: ReciveBorderColor, width: 0.5),
  837. color: isLongPressed ? Colors.grey[300] : Colors.white,
  838. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  839. ),
  840. msg.transTag != 1 && msg.transTag != 0
  841. ? Positioned(
  842. right: 5,
  843. top: 5,
  844. child: Container(
  845. child: Row(children: <Widget>[
  846. blueDot(curTextType == 0),
  847. blueDot(curTextType == 1),
  848. blueDot(curTextType == 2),
  849. //blueDot(true),
  850. ])))
  851. : Container()
  852. ]);
  853. return InkWell(
  854. child: text,
  855. onTap: () {
  856. MessageMgr().emit('Keyboard Hide');
  857. if (msg.transTag == 1) {
  858. return;
  859. }
  860. if (msg.transTag == 2 || msg.transTag == 3) {
  861. setState(() {
  862. curTextType += 1;
  863. curTextType %= textList.length;
  864. });
  865. return;
  866. }
  867. },
  868. );
  869. }
  870. //用户评价人工翻译,差评
  871. rateTranslateResult() async {
  872. return await HttpUtil().rateTranslateResult(widget.msg, () {
  873. if (mounted) {
  874. setState(() {});
  875. }
  876. });
  877. }
  878. _translateItemWidget(int code, String title, Function onTap) {
  879. Color color = onTap == null ? Color(0xFFC5C5C5) : Color(0xFF6A6A6A);
  880. return InkWell(
  881. onTap: onTap,
  882. splashColor: Colors.red,
  883. child: Container(
  884. width: 80,
  885. child: Row(
  886. children: <Widget>[
  887. Icon(
  888. IconData(code, fontFamily: Constants.IconFontFamily),
  889. color: color,
  890. size: 20,
  891. ),
  892. SizedBox(width: 5),
  893. Expanded(
  894. child: SizedBox(
  895. child: Text(
  896. title,
  897. style: TextStyle(color: color, fontSize: 10),
  898. textScaleFactor: 1.0,
  899. maxLines: 1,
  900. overflow: TextOverflow.ellipsis,
  901. ),
  902. ))
  903. ],
  904. )));
  905. }
  906. bool isTranslating = false;
  907. _transProcessWidget(int transTag) {
  908. double width = 160;
  909. Widget userTranslateWidget;
  910. Widget machineTranslateWidget;
  911. if (transTag == 1) {
  912. //机器翻译中
  913. userTranslateWidget =
  914. _translateItemWidget(0xe670, I18n.of(context).man_retranslate, null);
  915. machineTranslateWidget =
  916. _translateItemWidget(0xe671, I18n.of(context).robotTranslate, null);
  917. } else if (transTag == 2) {
  918. //人工翻译中
  919. userTranslateWidget =
  920. _translateItemWidget(0xe670, I18n.of(context).ManTranslate, null);
  921. machineTranslateWidget = _translateItemWidget(
  922. 0xe671,
  923. I18n.of(context).robot_retranslate,
  924. textList.length <= 1
  925. ? null
  926. : () {
  927. setState(() {
  928. curTextType += 1;
  929. curTextType %= textList.length;
  930. });
  931. });
  932. } else if (transTag == 3) {
  933. //机器翻译完成
  934. userTranslateWidget = _translateItemWidget(
  935. 0xe670,
  936. I18n.of(context).man_retranslate,
  937. isTranslating
  938. ? null
  939. : () async {
  940. isTranslating = true;
  941. int money =
  942. Provider.of<MoneyChangeProvider>(context, listen: false)
  943. .money;
  944. int voucher =
  945. Provider.of<VoucherChangeProvider>(context, listen: false)
  946. .voucher;
  947. int needMoney = widget.msg.getNeedMoney();
  948. if (needMoney > voucher + money) {
  949. showToast('翻译券和H币不足');
  950. return;
  951. }
  952. var res = await HttpUtil().getPersonalTranslate(widget.msg);
  953. if (res) {
  954. print('请求人工翻译成功,进行扣费');
  955. setState(() {
  956. widget.msg.transTag = 2;
  957. //优先扣券
  958. if (voucher > 0) {
  959. int costQuan = min(voucher, needMoney);
  960. Provider.of<VoucherChangeProvider>(context,
  961. listen: false)
  962. .subVoucher(costQuan);
  963. }
  964. //不足的话再扣H币
  965. if (needMoney > voucher) {
  966. Provider.of<MoneyChangeProvider>(context, listen: false)
  967. .subMoney(needMoney - voucher);
  968. }
  969. });
  970. }
  971. });
  972. machineTranslateWidget = _translateItemWidget(
  973. 0xe671,
  974. I18n.of(context).robot_retranslate,
  975. textList.length <= 1
  976. ? null
  977. : () {
  978. setState(() {
  979. curTextType += 1;
  980. curTextType %= textList.length;
  981. });
  982. });
  983. } else if (transTag == 4 || transTag == 10) {
  984. //4人工翻译完成,未评论 10人工翻译完成已评论
  985. userTranslateWidget = InkWell(
  986. onTap: () {
  987. setState(() {
  988. curTextType = 0;
  989. });
  990. },
  991. child: Container(
  992. width: width / 2,
  993. child: Row(
  994. children: <Widget>[
  995. InkWell(
  996. child: Icon(
  997. IconData(0xe641, fontFamily: Constants.IconFontFamily),
  998. size: 18,
  999. color:
  1000. transTag == 10 ? Colors.grey : Color(0xFF087FF3)),
  1001. onTap: transTag == 10
  1002. ? null
  1003. : () {
  1004. CustomUI.showIosDialog(
  1005. context, I18n.of(context).bad_ev, () async {
  1006. bool isSuccess = await rateTranslateResult();
  1007. if (isSuccess) {
  1008. Navigator.of(context).pop(true);
  1009. showToast(I18n.of(context).success);
  1010. } else {
  1011. showToast(I18n.of(context).fail);
  1012. Navigator.of(context).pop();
  1013. }
  1014. }, () {
  1015. Navigator.of(context).pop();
  1016. });
  1017. },
  1018. ),
  1019. SizedBox(width: 5),
  1020. Expanded(
  1021. child: SizedBox(
  1022. child: Text(
  1023. I18n.of(context).over,
  1024. style: TextStyle(color: Color(0xFF087FF3), fontSize: 10),
  1025. textScaleFactor: 1.0,
  1026. maxLines: 1,
  1027. overflow: TextOverflow.ellipsis,
  1028. ),
  1029. ))
  1030. ],
  1031. )));
  1032. machineTranslateWidget =
  1033. _translateItemWidget(0xe675, I18n.of(context).see_original, () {
  1034. setState(() {
  1035. curTextType = textList.length - 1;
  1036. });
  1037. });
  1038. }
  1039. return Container(
  1040. height: 26,
  1041. alignment: Alignment.center,
  1042. child: Row(
  1043. children: <Widget>[
  1044. userTranslateWidget,
  1045. Expanded(
  1046. child: SizedBox(child: VerticalDivider(), height: 20, width: 2)),
  1047. machineTranslateWidget
  1048. ],
  1049. ),
  1050. );
  1051. }
  1052. _receiveImg(BuildContext context, List<int> imgData, {String downloadData}) {
  1053. // ImageProvider provider = MemoryImage(Uint8List.fromList(imgData));
  1054. ImageProvider provider = MemoryImage(widget.msg.localFile == null
  1055. ? Uint8List.fromList(imgData)
  1056. : File(widget.msg.localFile).readAsBytesSync());
  1057. var imgSize = _getImgSize();
  1058. return DownloadItem(
  1059. isAutoDown: false,
  1060. msg: widget.msg,
  1061. onFinishTap: () {
  1062. widget.hideKeyboard();
  1063. showFullImg(context, widget.msg);
  1064. },
  1065. child: Container(
  1066. alignment: Alignment.centerLeft,
  1067. width: imgSize.width,
  1068. height: imgSize.height,
  1069. child: ClipRRect(
  1070. child: Image(
  1071. image: provider ?? AssetImage(R.assetsImagesIcAlbum),
  1072. ),
  1073. borderRadius: BorderRadius.circular(5),
  1074. ),
  1075. ),
  1076. );
  1077. }
  1078. _receiveVideo(BuildContext context, List<int> imgData,
  1079. {String downloadData}) {
  1080. ImageProvider provider = MemoryImage(Uint8List.fromList(imgData));
  1081. var imgSize = _getImgSize();
  1082. return InkWell(
  1083. onTap: () {
  1084. if (widget.msg.localFile != null) {
  1085. showVideoPage(context, widget.msg.localFile);
  1086. }
  1087. },
  1088. child: DownloadItem(
  1089. isAutoDown: false,
  1090. msg: widget.msg,
  1091. child: Container(
  1092. width: imgSize.width,
  1093. height: imgSize.height,
  1094. child: ClipRRect(
  1095. child: Image(
  1096. image: provider ?? AssetImage(R.assetsImagesIcAlbum),
  1097. ),
  1098. borderRadius: BorderRadius.circular(5),
  1099. ),
  1100. ),
  1101. ));
  1102. }
  1103. showVideoPage(BuildContext context, String filePath) {
  1104. widget.hideKeyboard();
  1105. Navigator.push(context,
  1106. MaterialPageRoute<void>(builder: (BuildContext context) {
  1107. return VideoPage(videoPath: filePath);
  1108. }));
  1109. }
  1110. _receiveSound(BuildContext context, List<int> soundData) {
  1111. print(' build 收到的语音消息');
  1112. MsgModel msg = widget.msg;
  1113. var time = widget.msg.extraInfo / 1000;
  1114. if (time > 60) {
  1115. time = 60.0;
  1116. }
  1117. bool isPlaying = false;
  1118. if (curSoundUrl != null) {
  1119. isPlaying = SoundUtils().isPlaying(curSoundUrl);
  1120. }
  1121. var soundWidget = InkWell(
  1122. onTap: () async {
  1123. bool isLocal = true;
  1124. if (msg.localFile != null) {
  1125. isLocal = true;
  1126. curSoundUrl = msg.localFile;
  1127. } else {
  1128. isLocal = false;
  1129. var sessionId = msg.sessionId;
  1130. curSoundUrl = UploadUtil()
  1131. .getFullUrl(msg.extraFile, sessionId, msg.channelType);
  1132. }
  1133. print('当前文件$curSoundUrl 本地?$isLocal');
  1134. if (isPlaying) {
  1135. await SoundUtils().pause();
  1136. } else {
  1137. print('开始播放');
  1138. if (widget.msg.soundListened == 0) {
  1139. widget.msg.updateSoundListened();
  1140. }
  1141. await SoundUtils().play(curSoundUrl, isLocal: isLocal, onPlayed: () {
  1142. if (mounted) {
  1143. this.setState(() {});
  1144. }
  1145. }, complete: () {
  1146. if (mounted) {
  1147. this.setState(() {});
  1148. }
  1149. });
  1150. }
  1151. },
  1152. child: Container(
  1153. width: 130,
  1154. child: Row(children: <Widget>[
  1155. Container(
  1156. alignment: Alignment.center,
  1157. padding: EdgeInsets.only(bottom: 2),
  1158. margin: EdgeInsets.only(right: 10),
  1159. width: 25.5,
  1160. height: 25.5,
  1161. decoration: BoxDecoration(
  1162. border:
  1163. Border.all(color: const Color(0xFF1B92C7), width: 0.5),
  1164. color: const Color(0xFF04A4FE),
  1165. shape: BoxShape.circle),
  1166. child: Icon(
  1167. IconData(isPlaying ? 0xe652 : 0xe653,
  1168. fontFamily: Constants.IconFontFamily),
  1169. size: isPlaying ? 15 : 18,
  1170. color: Colors.white,
  1171. ),
  1172. ),
  1173. isPlaying
  1174. ? Stack(
  1175. children: <Widget>[
  1176. Container(
  1177. height: 18,
  1178. width: 19,
  1179. ),
  1180. Positioned(
  1181. bottom: 0,
  1182. child: VideoAnim(
  1183. begin: 18,
  1184. start: 0.444,
  1185. end: 4.5,
  1186. )),
  1187. Positioned(
  1188. left: 7,
  1189. bottom: 0,
  1190. child: VideoAnim(
  1191. begin: 4.5,
  1192. end: 18,
  1193. )),
  1194. Positioned(
  1195. left: 14,
  1196. bottom: 0,
  1197. child: VideoAnim(
  1198. begin: 18,
  1199. end: 4.5,
  1200. ))
  1201. ],
  1202. )
  1203. : Stack(
  1204. children: <Widget>[
  1205. Container(
  1206. height: 18,
  1207. width: 19,
  1208. ),
  1209. Positioned(
  1210. bottom: 0, child: CustomUI.buildAudioContaniner(12)),
  1211. Positioned(
  1212. left: 7,
  1213. bottom: 0,
  1214. child: CustomUI.buildAudioContaniner(4.5)),
  1215. Positioned(
  1216. left: 14,
  1217. bottom: 0,
  1218. child: CustomUI.buildAudioContaniner(18))
  1219. ],
  1220. ),
  1221. Expanded(child: SizedBox()),
  1222. fixedText(time.toStringAsFixed(0),
  1223. color: Constants.BlackTextColor, fontSize: 16)
  1224. ])),
  1225. );
  1226. List<Widget> showMsg = [];
  1227. showMsg.add(DownloadItem(
  1228. msg: widget.msg,
  1229. child: soundWidget,
  1230. isShowProgress: false,
  1231. ));
  1232. double width = 130;
  1233. double minWidth = 0;
  1234. if (textList.length > 0) {
  1235. width = _getTextWidth(textList[curTextType]) + 20;
  1236. width = min(width, Screen.width - 120);
  1237. minWidth = max(width, 150);
  1238. showMsg.add(Padding(
  1239. padding: EdgeInsets.symmetric(vertical: 5),
  1240. child: Divider(
  1241. height: 1,
  1242. )));
  1243. showMsg.add(Container(
  1244. child: extendedText(
  1245. textList[curTextType],
  1246. color: Constants.BlackTextColor,
  1247. hideKeyboard: widget.hideKeyboard,
  1248. fontSize: FontSize,
  1249. ),
  1250. alignment: Alignment.centerLeft,
  1251. constraints:
  1252. BoxConstraints(maxWidth: Screen.width - 120, minHeight: 22),
  1253. ));
  1254. }
  1255. if (msg.transTag != 0) {
  1256. minWidth = 200;
  1257. showMsg.add(Divider(color: Color(0xFFECECEC), height: 3));
  1258. Widget tranWidget = _transProcessWidget(msg.transTag);
  1259. showMsg.add(tranWidget);
  1260. }
  1261. return Container(
  1262. width: width + 20,
  1263. constraints:
  1264. msg.transTag != 0 ? BoxConstraints(minWidth: minWidth) : null,
  1265. child: Column(
  1266. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  1267. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  1268. decoration: BoxDecoration(
  1269. color: Colors.white,
  1270. border: Border.all(color: ReciveBorderColor, width: 0.5),
  1271. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  1272. );
  1273. }
  1274. void showFullImg(BuildContext context, MsgModel msg) {
  1275. print('显示图片');
  1276. Navigator.push(context,
  1277. MaterialPageRoute<void>(builder: (BuildContext context) {
  1278. return PhotoPage(msg: msg);
  1279. }));
  1280. }
  1281. _reveiveMsg(BuildContext context) {
  1282. Widget item;
  1283. switch (ChatType.valueOf(widget.msg.msgType)) {
  1284. case ChatType.TextChatType:
  1285. item = _receiveText(widget.msg);
  1286. break;
  1287. case ChatType.EmoticonType:
  1288. item = _receiveJIF(widget.msg);
  1289. break;
  1290. case ChatType.ImageChatType:
  1291. if (widget.msg.extraFile != null) {
  1292. item = _receiveImg(context, widget.msg.msgContent,
  1293. downloadData: widget.msg.extraFile);
  1294. } else {
  1295. item = _receiveImg(context, widget.msg.msgContent);
  1296. }
  1297. break;
  1298. case ChatType.ShortVideoChatType:
  1299. item = _receiveVideo(context, widget.msg.msgContent,
  1300. downloadData: widget.msg.extraFile);
  1301. break;
  1302. case ChatType.ShortVoiceChatType:
  1303. item = _receiveSound(context, widget.msg.msgContent);
  1304. break;
  1305. case ChatType.PlaceChatType:
  1306. item = PlaceItem(isMe: false, placeContent: widget.msg.msgContent);
  1307. break;
  1308. case ChatType.FileChatType:
  1309. item = _receiveFileMsgItem();
  1310. break;
  1311. default:
  1312. }
  1313. return wrapItemWithMenu(item);
  1314. }
  1315. Widget _receiveFileMsgItem() {
  1316. return DownloadItem(
  1317. isAutoDown: false,
  1318. msg: widget.msg,
  1319. onComplete: () {
  1320. if (mounted) {
  1321. setState(() {});
  1322. }
  1323. },
  1324. child: Container(
  1325. height: 100,
  1326. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  1327. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  1328. decoration: BoxDecoration(
  1329. color: Colors.white,
  1330. border: Border.all(color: ReciveBorderColor, width: 0.5),
  1331. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  1332. child: FileMsgItem(widget.msg)));
  1333. }
  1334. Widget _getReceivedMessageLayout(BuildContext context) {
  1335. bool hasHeadImg = true;
  1336. var memberModel = widget.memberModel;
  1337. if (memberModel == null) {
  1338. return Container();
  1339. }
  1340. if (memberModel.avtar == null || memberModel.avtar.length == 0) {
  1341. hasHeadImg = false;
  1342. }
  1343. GroupInfoModel infoModel = Provider.of<GroupInfoModel>(context);
  1344. var refName = Provider.of<RefNameProvider>(context)
  1345. .getGroupRefName(infoModel.sessionId, memberModel.memberId);
  1346. bool isShowSoundSate =
  1347. widget.msg.msgType == ChatType.ShortVoiceChatType.value &&
  1348. widget.msg.soundListened == 0;
  1349. return Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
  1350. Container(
  1351. margin: const EdgeInsets.only(right: 8.0),
  1352. child: GestureDetector(
  1353. child: ClipRRect(
  1354. borderRadius: BorderRadius.circular(8),
  1355. child: hasHeadImg
  1356. ? CachedNetworkImage(
  1357. imageUrl: memberModel.avtar,
  1358. placeholder: (context, url) => Image.asset(
  1359. Constants.DefaultHeadImgUrl,
  1360. width: 40,
  1361. height: 40,
  1362. ),
  1363. width: 40,
  1364. height: 40,
  1365. )
  1366. : SizedBox(
  1367. width: 40,
  1368. height: 40,
  1369. child: Image.asset(R.assetsImagesDefaultNorAvatar))),
  1370. onTap: () {
  1371. AppNavigator.pushProfileInfoPage(context, memberModel.memberId,
  1372. fromWhere: 2,
  1373. addMode: !FriendListMgr().isMyFriend(memberModel.memberId)
  1374. ? 1
  1375. : 0);
  1376. },
  1377. onLongPress: () {
  1378. print('long press user');
  1379. MessageMgr().emit('Alter User Message', memberModel);
  1380. },
  1381. )),
  1382. infoModel.isShowName > 0
  1383. ? Column(
  1384. crossAxisAlignment: CrossAxisAlignment.start,
  1385. children: <Widget>[
  1386. Container(
  1387. padding: EdgeInsets.only(left: 9),
  1388. child: fixedText(refName, fontSize: 12, color: Colors.grey),
  1389. ),
  1390. SizedBox(height: 2),
  1391. _reveiveMsg(context),
  1392. ],
  1393. )
  1394. : _reveiveMsg(context),
  1395. isShowSoundSate
  1396. ? Container(
  1397. margin: EdgeInsets.only(
  1398. left: 8, top: infoModel.isShowName > 0 ? 38 : 20),
  1399. child: CircleAvatar(
  1400. radius: 3.5,
  1401. backgroundColor: Colors.red,
  1402. ))
  1403. : Container()
  1404. ]);
  1405. }
  1406. }