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.
 
 
 
 
 
 

1544 regels
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. width = min(max(contentWidth, width), maxWidth);
  806. showMsg.add(Container(
  807. constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
  808. alignment: Alignment.centerLeft,
  809. child: extendedText(
  810. textList[curTextType],
  811. color: isUrl ? Colors.blue : Constants.BlackTextColor,
  812. hideKeyboard: widget.hideKeyboard,
  813. fontSize: FontSize,
  814. )));
  815. }
  816. var minWidth = width + 20;
  817. if (msg.transTag != 0) {
  818. minWidth = 200;
  819. showMsg.add(Padding(
  820. padding: EdgeInsets.symmetric(vertical: 5),
  821. child: Divider(color: Color(0xFFECECEC), height: 1)));
  822. Widget tranWidget = _transProcessWidget(msg.transTag);
  823. showMsg.add(tranWidget);
  824. }
  825. Widget text = Stack(children: <Widget>[
  826. Container(
  827. width: width + 20,
  828. constraints:
  829. BoxConstraints(maxWidth: Screen.width - 120, minWidth: minWidth),
  830. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  831. child: Column(
  832. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  833. decoration: BoxDecoration(
  834. border: Border.all(color: ReciveBorderColor, width: 0.5),
  835. color: isLongPressed ? Colors.grey[300] : Colors.white,
  836. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  837. ),
  838. msg.transTag != 1 && msg.transTag != 0
  839. ? Positioned(
  840. right: 5,
  841. top: 5,
  842. child: Container(
  843. child: Row(children: <Widget>[
  844. blueDot(curTextType == 0),
  845. blueDot(curTextType == 1),
  846. blueDot(curTextType == 2),
  847. //blueDot(true),
  848. ])))
  849. : Container()
  850. ]);
  851. return InkWell(
  852. child: text,
  853. onTap: () {
  854. MessageMgr().emit('Keyboard Hide');
  855. if (msg.transTag == 1) {
  856. return;
  857. }
  858. if (msg.transTag == 2 || msg.transTag == 3) {
  859. setState(() {
  860. curTextType += 1;
  861. curTextType %= textList.length;
  862. });
  863. return;
  864. }
  865. },
  866. );
  867. }
  868. //用户评价人工翻译,差评
  869. rateTranslateResult() async {
  870. return await HttpUtil().rateTranslateResult(widget.msg, () {
  871. if (mounted) {
  872. setState(() {});
  873. }
  874. });
  875. }
  876. _translateItemWidget(int code, String title, Function onTap) {
  877. Color color = onTap == null ? Color(0xFFC5C5C5) : Color(0xFF6A6A6A);
  878. return InkWell(
  879. onTap: onTap,
  880. splashColor: Colors.red,
  881. child: Container(
  882. width: 80,
  883. child: Row(
  884. children: <Widget>[
  885. Icon(
  886. IconData(code, fontFamily: Constants.IconFontFamily),
  887. color: color,
  888. size: 20,
  889. ),
  890. SizedBox(width: 5),
  891. Expanded(
  892. child: SizedBox(
  893. child: Text(
  894. title,
  895. style: TextStyle(color: color, fontSize: 10),
  896. textScaleFactor: 1.0,
  897. maxLines: 1,
  898. overflow: TextOverflow.ellipsis,
  899. ),
  900. ))
  901. ],
  902. )));
  903. }
  904. bool isTranslating = false;
  905. _transProcessWidget(int transTag) {
  906. double width = 160;
  907. Widget userTranslateWidget;
  908. Widget machineTranslateWidget;
  909. if (transTag == 1) {
  910. //机器翻译中
  911. userTranslateWidget =
  912. _translateItemWidget(0xe670, I18n.of(context).man_retranslate, null);
  913. machineTranslateWidget =
  914. _translateItemWidget(0xe671, I18n.of(context).robotTranslate, null);
  915. } else if (transTag == 2) {
  916. //人工翻译中
  917. userTranslateWidget =
  918. _translateItemWidget(0xe670, I18n.of(context).ManTranslate, null);
  919. machineTranslateWidget = _translateItemWidget(
  920. 0xe671,
  921. I18n.of(context).robot_retranslate,
  922. textList.length <= 1
  923. ? null
  924. : () {
  925. setState(() {
  926. curTextType += 1;
  927. curTextType %= textList.length;
  928. });
  929. });
  930. } else if (transTag == 3) {
  931. //机器翻译完成
  932. userTranslateWidget = _translateItemWidget(
  933. 0xe670,
  934. I18n.of(context).man_retranslate,
  935. isTranslating
  936. ? null
  937. : () async {
  938. isTranslating = true;
  939. int money =
  940. Provider.of<MoneyChangeProvider>(context, listen: false)
  941. .money;
  942. int voucher =
  943. Provider.of<VoucherChangeProvider>(context, listen: false)
  944. .voucher;
  945. int needMoney = widget.msg.getNeedMoney();
  946. if (needMoney > voucher + money) {
  947. showToast('翻译券和H币不足');
  948. return;
  949. }
  950. var res = await HttpUtil().getPersonalTranslate(widget.msg);
  951. if (res) {
  952. print('请求人工翻译成功,进行扣费');
  953. setState(() {
  954. widget.msg.transTag = 2;
  955. //优先扣券
  956. if (voucher > 0) {
  957. int costQuan = min(voucher, needMoney);
  958. Provider.of<VoucherChangeProvider>(context,
  959. listen: false)
  960. .subVoucher(costQuan);
  961. }
  962. //不足的话再扣H币
  963. if (needMoney > voucher) {
  964. Provider.of<MoneyChangeProvider>(context, listen: false)
  965. .subMoney(needMoney - voucher);
  966. }
  967. });
  968. }
  969. });
  970. machineTranslateWidget = _translateItemWidget(
  971. 0xe671,
  972. I18n.of(context).robot_retranslate,
  973. textList.length <= 1
  974. ? null
  975. : () {
  976. setState(() {
  977. curTextType += 1;
  978. curTextType %= textList.length;
  979. });
  980. });
  981. } else if (transTag == 4 || transTag == 10) {
  982. //4人工翻译完成,未评论 10人工翻译完成已评论
  983. userTranslateWidget = InkWell(
  984. onTap: () {
  985. setState(() {
  986. curTextType = 0;
  987. });
  988. },
  989. child: Container(
  990. width: width / 2,
  991. child: Row(
  992. children: <Widget>[
  993. InkWell(
  994. child: Icon(
  995. IconData(0xe641, fontFamily: Constants.IconFontFamily),
  996. size: 18,
  997. color:
  998. transTag == 10 ? Colors.grey : Color(0xFF087FF3)),
  999. onTap: transTag == 10
  1000. ? null
  1001. : () {
  1002. CustomUI.showIosDialog(
  1003. context, I18n.of(context).bad_ev, () async {
  1004. bool isSuccess = await rateTranslateResult();
  1005. if (isSuccess) {
  1006. Navigator.of(context).pop(true);
  1007. showToast(I18n.of(context).success);
  1008. } else {
  1009. showToast(I18n.of(context).fail);
  1010. Navigator.of(context).pop();
  1011. }
  1012. }, () {
  1013. Navigator.of(context).pop();
  1014. });
  1015. },
  1016. ),
  1017. SizedBox(width: 5),
  1018. Expanded(
  1019. child: SizedBox(
  1020. child: Text(
  1021. I18n.of(context).over,
  1022. style: TextStyle(color: Color(0xFF087FF3), fontSize: 10),
  1023. textScaleFactor: 1.0,
  1024. maxLines: 1,
  1025. overflow: TextOverflow.ellipsis,
  1026. ),
  1027. ))
  1028. ],
  1029. )));
  1030. machineTranslateWidget =
  1031. _translateItemWidget(0xe675, I18n.of(context).see_original, () {
  1032. setState(() {
  1033. curTextType = textList.length - 1;
  1034. });
  1035. });
  1036. }
  1037. return Container(
  1038. height: 26,
  1039. alignment: Alignment.center,
  1040. child: Row(
  1041. children: <Widget>[
  1042. userTranslateWidget,
  1043. Expanded(
  1044. child: SizedBox(child: VerticalDivider(), height: 20, width: 2)),
  1045. machineTranslateWidget
  1046. ],
  1047. ),
  1048. );
  1049. }
  1050. _receiveImg(BuildContext context, List<int> imgData, {String downloadData}) {
  1051. // ImageProvider provider = MemoryImage(Uint8List.fromList(imgData));
  1052. ImageProvider provider = MemoryImage(widget.msg.localFile == null
  1053. ? Uint8List.fromList(imgData)
  1054. : File(widget.msg.localFile).readAsBytesSync());
  1055. var imgSize = _getImgSize();
  1056. return DownloadItem(
  1057. isAutoDown: false,
  1058. msg: widget.msg,
  1059. onFinishTap: () {
  1060. widget.hideKeyboard();
  1061. showFullImg(context, widget.msg);
  1062. },
  1063. child: Container(
  1064. alignment: Alignment.centerLeft,
  1065. width: imgSize.width,
  1066. height: imgSize.height,
  1067. child: ClipRRect(
  1068. child: Image(
  1069. image: provider ?? AssetImage(R.assetsImagesIcAlbum),
  1070. ),
  1071. borderRadius: BorderRadius.circular(5),
  1072. ),
  1073. ),
  1074. );
  1075. }
  1076. _receiveVideo(BuildContext context, List<int> imgData,
  1077. {String downloadData}) {
  1078. ImageProvider provider = MemoryImage(Uint8List.fromList(imgData));
  1079. var imgSize = _getImgSize();
  1080. return InkWell(
  1081. onTap: () {
  1082. if (widget.msg.localFile != null) {
  1083. showVideoPage(context, widget.msg.localFile);
  1084. }
  1085. },
  1086. child: DownloadItem(
  1087. isAutoDown: false,
  1088. msg: widget.msg,
  1089. child: Container(
  1090. width: imgSize.width,
  1091. height: imgSize.height,
  1092. child: ClipRRect(
  1093. child: Image(
  1094. image: provider ?? AssetImage(R.assetsImagesIcAlbum),
  1095. ),
  1096. borderRadius: BorderRadius.circular(5),
  1097. ),
  1098. ),
  1099. ));
  1100. }
  1101. showVideoPage(BuildContext context, String filePath) {
  1102. widget.hideKeyboard();
  1103. Navigator.push(context,
  1104. MaterialPageRoute<void>(builder: (BuildContext context) {
  1105. return VideoPage(videoPath: filePath);
  1106. }));
  1107. }
  1108. _receiveSound(BuildContext context, List<int> soundData) {
  1109. print(' build 收到的语音消息');
  1110. MsgModel msg = widget.msg;
  1111. var time = widget.msg.extraInfo / 1000;
  1112. if (time > 60) {
  1113. time = 60.0;
  1114. }
  1115. bool isPlaying = false;
  1116. if (curSoundUrl != null) {
  1117. isPlaying = SoundUtils().isPlaying(curSoundUrl);
  1118. }
  1119. var soundWidget = InkWell(
  1120. onTap: () async {
  1121. bool isLocal = true;
  1122. if (msg.localFile != null) {
  1123. isLocal = true;
  1124. curSoundUrl = msg.localFile;
  1125. } else {
  1126. isLocal = false;
  1127. var sessionId = msg.sessionId;
  1128. curSoundUrl = UploadUtil()
  1129. .getFullUrl(msg.extraFile, sessionId, msg.channelType);
  1130. }
  1131. print('当前文件$curSoundUrl 本地?$isLocal');
  1132. if (isPlaying) {
  1133. await SoundUtils().pause();
  1134. } else {
  1135. print('开始播放');
  1136. if (widget.msg.soundListened == 0) {
  1137. widget.msg.updateSoundListened();
  1138. }
  1139. await SoundUtils().play(curSoundUrl, isLocal: isLocal, onPlayed: () {
  1140. if (mounted) {
  1141. this.setState(() {});
  1142. }
  1143. }, complete: () {
  1144. if (mounted) {
  1145. this.setState(() {});
  1146. }
  1147. });
  1148. }
  1149. },
  1150. child: Container(
  1151. width: 130,
  1152. child: Row(children: <Widget>[
  1153. Container(
  1154. alignment: Alignment.center,
  1155. padding: EdgeInsets.only(bottom: 2),
  1156. margin: EdgeInsets.only(right: 10),
  1157. width: 25.5,
  1158. height: 25.5,
  1159. decoration: BoxDecoration(
  1160. border:
  1161. Border.all(color: const Color(0xFF1B92C7), width: 0.5),
  1162. color: const Color(0xFF04A4FE),
  1163. shape: BoxShape.circle),
  1164. child: Icon(
  1165. IconData(isPlaying ? 0xe652 : 0xe653,
  1166. fontFamily: Constants.IconFontFamily),
  1167. size: isPlaying ? 15 : 18,
  1168. color: Colors.white,
  1169. ),
  1170. ),
  1171. isPlaying
  1172. ? Stack(
  1173. children: <Widget>[
  1174. Container(
  1175. height: 18,
  1176. width: 19,
  1177. ),
  1178. Positioned(
  1179. bottom: 0,
  1180. child: VideoAnim(
  1181. begin: 18,
  1182. start: 0.444,
  1183. end: 4.5,
  1184. )),
  1185. Positioned(
  1186. left: 7,
  1187. bottom: 0,
  1188. child: VideoAnim(
  1189. begin: 4.5,
  1190. end: 18,
  1191. )),
  1192. Positioned(
  1193. left: 14,
  1194. bottom: 0,
  1195. child: VideoAnim(
  1196. begin: 18,
  1197. end: 4.5,
  1198. ))
  1199. ],
  1200. )
  1201. : Stack(
  1202. children: <Widget>[
  1203. Container(
  1204. height: 18,
  1205. width: 19,
  1206. ),
  1207. Positioned(
  1208. bottom: 0, child: CustomUI.buildAudioContaniner(12)),
  1209. Positioned(
  1210. left: 7,
  1211. bottom: 0,
  1212. child: CustomUI.buildAudioContaniner(4.5)),
  1213. Positioned(
  1214. left: 14,
  1215. bottom: 0,
  1216. child: CustomUI.buildAudioContaniner(18))
  1217. ],
  1218. ),
  1219. Expanded(child: SizedBox()),
  1220. fixedText(time.toStringAsFixed(0),
  1221. color: Constants.BlackTextColor, fontSize: 16)
  1222. ])),
  1223. );
  1224. List<Widget> showMsg = [];
  1225. showMsg.add(DownloadItem(
  1226. msg: widget.msg,
  1227. child: soundWidget,
  1228. isShowProgress: false,
  1229. ));
  1230. double width = 130;
  1231. double minWidth = 0;
  1232. if (textList.length > 0) {
  1233. width = _getTextWidth(textList[curTextType]) + 20;
  1234. width = min(width, Screen.width - 120);
  1235. minWidth = max(width, 150);
  1236. showMsg.add(Padding(
  1237. padding: EdgeInsets.symmetric(vertical: 5),
  1238. child: Divider(
  1239. height: 1,
  1240. )));
  1241. showMsg.add(Container(
  1242. child: extendedText(
  1243. textList[curTextType],
  1244. color: Constants.BlackTextColor,
  1245. hideKeyboard: widget.hideKeyboard,
  1246. fontSize: FontSize,
  1247. ),
  1248. alignment: Alignment.centerLeft,
  1249. constraints:
  1250. BoxConstraints(maxWidth: Screen.width - 120, minHeight: 22),
  1251. ));
  1252. }
  1253. if (msg.transTag != 0) {
  1254. minWidth = 200;
  1255. showMsg.add(Divider(color: Color(0xFFECECEC), height: 3));
  1256. Widget tranWidget = _transProcessWidget(msg.transTag);
  1257. showMsg.add(tranWidget);
  1258. }
  1259. return Container(
  1260. width: width + 20,
  1261. constraints:
  1262. msg.transTag != 0 ? BoxConstraints(minWidth: minWidth) : null,
  1263. child: Column(
  1264. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  1265. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  1266. decoration: BoxDecoration(
  1267. color: Colors.white,
  1268. border: Border.all(color: ReciveBorderColor, width: 0.5),
  1269. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  1270. );
  1271. }
  1272. void showFullImg(BuildContext context, MsgModel msg) {
  1273. print('显示图片');
  1274. Navigator.push(context,
  1275. MaterialPageRoute<void>(builder: (BuildContext context) {
  1276. return PhotoPage(msg: msg);
  1277. }));
  1278. }
  1279. _reveiveMsg(BuildContext context) {
  1280. Widget item;
  1281. switch (ChatType.valueOf(widget.msg.msgType)) {
  1282. case ChatType.TextChatType:
  1283. item = _receiveText(widget.msg);
  1284. break;
  1285. case ChatType.EmoticonType:
  1286. item = _receiveJIF(widget.msg);
  1287. break;
  1288. case ChatType.ImageChatType:
  1289. if (widget.msg.extraFile != null) {
  1290. item = _receiveImg(context, widget.msg.msgContent,
  1291. downloadData: widget.msg.extraFile);
  1292. } else {
  1293. item = _receiveImg(context, widget.msg.msgContent);
  1294. }
  1295. break;
  1296. case ChatType.ShortVideoChatType:
  1297. item = _receiveVideo(context, widget.msg.msgContent,
  1298. downloadData: widget.msg.extraFile);
  1299. break;
  1300. case ChatType.ShortVoiceChatType:
  1301. item = _receiveSound(context, widget.msg.msgContent);
  1302. break;
  1303. case ChatType.PlaceChatType:
  1304. item = PlaceItem(isMe: false, placeContent: widget.msg.msgContent);
  1305. break;
  1306. case ChatType.FileChatType:
  1307. item = _receiveFileMsgItem();
  1308. break;
  1309. default:
  1310. }
  1311. return wrapItemWithMenu(item);
  1312. }
  1313. Widget _receiveFileMsgItem() {
  1314. return DownloadItem(
  1315. isAutoDown: false,
  1316. msg: widget.msg,
  1317. onComplete: () {
  1318. if (mounted) {
  1319. setState(() {});
  1320. }
  1321. },
  1322. child: Container(
  1323. height: 100,
  1324. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  1325. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  1326. decoration: BoxDecoration(
  1327. color: Colors.white,
  1328. border: Border.all(color: ReciveBorderColor, width: 0.5),
  1329. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  1330. child: FileMsgItem(widget.msg)));
  1331. }
  1332. Widget _getReceivedMessageLayout(BuildContext context) {
  1333. bool hasHeadImg = true;
  1334. var memberModel = widget.memberModel;
  1335. if (memberModel == null) {
  1336. return Container();
  1337. }
  1338. if (memberModel.avtar == null || memberModel.avtar.length == 0) {
  1339. hasHeadImg = false;
  1340. }
  1341. GroupInfoModel infoModel = Provider.of<GroupInfoModel>(context);
  1342. var refName = Provider.of<RefNameProvider>(context)
  1343. .getGroupRefName(infoModel.sessionId, memberModel.memberId);
  1344. bool isShowSoundSate =
  1345. widget.msg.msgType == ChatType.ShortVoiceChatType.value &&
  1346. widget.msg.soundListened == 0;
  1347. return Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
  1348. Container(
  1349. margin: const EdgeInsets.only(right: 8.0),
  1350. child: GestureDetector(
  1351. child: ClipRRect(
  1352. borderRadius: BorderRadius.circular(8),
  1353. child: hasHeadImg
  1354. ? CachedNetworkImage(
  1355. imageUrl: memberModel.avtar,
  1356. placeholder: (context, url) => Image.asset(
  1357. Constants.DefaultHeadImgUrl,
  1358. width: 40,
  1359. height: 40,
  1360. ),
  1361. width: 40,
  1362. height: 40,
  1363. )
  1364. : SizedBox(
  1365. width: 40,
  1366. height: 40,
  1367. child: Image.asset(R.assetsImagesDefaultNorAvatar))),
  1368. onTap: () {
  1369. AppNavigator.pushProfileInfoPage(context, memberModel.memberId,
  1370. fromWhere: 2,
  1371. addMode: !FriendListMgr().isMyFriend(memberModel.memberId)
  1372. ? 1
  1373. : 0);
  1374. },
  1375. onLongPress: () {
  1376. print('long press user');
  1377. MessageMgr().emit('Alter User Message', memberModel);
  1378. },
  1379. )),
  1380. infoModel.isShowName > 0
  1381. ? Column(
  1382. crossAxisAlignment: CrossAxisAlignment.start,
  1383. children: <Widget>[
  1384. Container(
  1385. padding: EdgeInsets.only(left: 9),
  1386. child: fixedText(refName, fontSize: 12, color: Colors.grey),
  1387. ),
  1388. SizedBox(height: 2),
  1389. _reveiveMsg(context),
  1390. ],
  1391. )
  1392. : _reveiveMsg(context),
  1393. isShowSoundSate
  1394. ? Container(
  1395. margin: EdgeInsets.only(
  1396. left: 8, top: infoModel.isShowName > 0 ? 38 : 20),
  1397. child: CircleAvatar(
  1398. radius: 3.5,
  1399. backgroundColor: Colors.red,
  1400. ))
  1401. : Container()
  1402. ]);
  1403. }
  1404. }