Hibok
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1547 lines
50 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. if (contentWidth > width && contentWidth <= maxWidth) {
  351. width = contentWidth;
  352. }
  353. showMsg.add(Container(
  354. constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
  355. alignment: Alignment.centerLeft,
  356. child: extendedText(
  357. textList[curTextType],
  358. color: isUrl ? Colors.blue : Constants.BlackTextColor,
  359. hideKeyboard: widget.hideKeyboard,
  360. fontSize: FontSize,
  361. )));
  362. return Container(
  363. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  364. width: width + 20,
  365. child: Column(
  366. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  367. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  368. decoration: BoxDecoration(
  369. color: isLongPressed ? Colors.grey[300] : SendMsgBg,
  370. border: Border.all(color: Color(0xFFB9CBD7), width: 0.6),
  371. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  372. );
  373. }
  374. _soundMsg() {
  375. double time = widget.msg.extraInfo / 1000;
  376. if (time > 60) {
  377. time = 60.0;
  378. }
  379. bool isPlaying = false;
  380. var soundPath = widget.msg.localFile;
  381. isPlaying = SoundUtils().isPlaying(soundPath);
  382. var soundWidget = GestureDetector(
  383. child: Container(
  384. width: 120,
  385. child: Row(
  386. mainAxisAlignment: MainAxisAlignment.end,
  387. children: <Widget>[
  388. Container(
  389. alignment: Alignment.center,
  390. padding: EdgeInsets.only(bottom: 2),
  391. margin: EdgeInsets.only(right: 10),
  392. width: 25.5,
  393. height: 25.5,
  394. decoration: BoxDecoration(
  395. border:
  396. Border.all(color: const Color(0xFF1B92C7), width: 0.5),
  397. color: const Color(0xFF04A4FE),
  398. shape: BoxShape.circle),
  399. child: Icon(
  400. IconData(isPlaying ? 0xe652 : 0xe653,
  401. fontFamily: Constants.IconFontFamily),
  402. size: isPlaying ? 15 : 18,
  403. color: Colors.white,
  404. ),
  405. ),
  406. isPlaying
  407. ? Stack(
  408. children: <Widget>[
  409. Container(
  410. height: 18,
  411. width: 19,
  412. ),
  413. Positioned(
  414. bottom: 0,
  415. child: VideoAnim(
  416. begin: 18,
  417. start: 0.444,
  418. end: 4.5,
  419. )),
  420. Positioned(
  421. left: 7,
  422. bottom: 0,
  423. child: VideoAnim(
  424. begin: 4.5,
  425. end: 18,
  426. )),
  427. Positioned(
  428. left: 14,
  429. bottom: 0,
  430. child: VideoAnim(
  431. begin: 18,
  432. end: 4.5,
  433. ))
  434. ],
  435. )
  436. : Stack(
  437. children: <Widget>[
  438. Container(
  439. height: 18,
  440. width: 19,
  441. ),
  442. Positioned(
  443. bottom: 0, child: CustomUI.buildAudioContaniner(12)),
  444. Positioned(
  445. left: 7,
  446. bottom: 0,
  447. child: CustomUI.buildAudioContaniner(4.5)),
  448. Positioned(
  449. left: 14,
  450. bottom: 0,
  451. child: CustomUI.buildAudioContaniner(18))
  452. ],
  453. ),
  454. Expanded(child: SizedBox()),
  455. fixedText(time.toStringAsFixed(0), color: SendMsgText, fontSize: 16)
  456. ],
  457. ),
  458. padding: EdgeInsets.symmetric(horizontal: 15, vertical: 12),
  459. decoration: BoxDecoration(
  460. color: SendMsgBg,
  461. border: Border.all(color: Color(0xFFB9CBD7), width: 0.6),
  462. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  463. ),
  464. onTap: () async {
  465. print('播放状态 : $isPlaying');
  466. print('当前文件$soundPath ');
  467. if (isPlaying) {
  468. SoundUtils().pause();
  469. } else {
  470. SoundUtils().play(soundPath, onPlayed: () {
  471. if (mounted) {
  472. setState(() {});
  473. }
  474. }, complete: () {
  475. if (mounted) {
  476. setState(() {});
  477. }
  478. });
  479. }
  480. },
  481. );
  482. return UploadImgItem(
  483. msg: widget.msg,
  484. child: soundWidget,
  485. isShowProgress: false,
  486. );
  487. }
  488. Size _getImgSize() {
  489. double aspectRatio = widget.msg.extraInfo / 100;
  490. var maxWidth = Screen.width * 0.65;
  491. var maxHeight = Screen.height / 4;
  492. var width, height;
  493. if (maxWidth / maxHeight > aspectRatio) {
  494. height = maxHeight;
  495. width = maxHeight * aspectRatio;
  496. } else {
  497. width = maxWidth;
  498. height = maxWidth / aspectRatio;
  499. }
  500. return Size(width, height);
  501. }
  502. _imgMsg(List<int> imgData) {
  503. var imgSize = _getImgSize();
  504. ImageProvider provider = MemoryImage(widget.msg.localFile == null
  505. ? Uint8List.fromList(imgData)
  506. : File(widget.msg.localFile).readAsBytesSync());
  507. return GestureDetector(
  508. child: ClipRRect(
  509. child: UploadImgItem(
  510. msg: widget.msg,
  511. cancelToken: _cancelToken,
  512. child: Container(
  513. height: imgSize.height,
  514. width: imgSize.width,
  515. child: Image(
  516. fit: BoxFit.contain,
  517. image: provider,
  518. ),
  519. )),
  520. borderRadius: BorderRadius.circular(5),
  521. ),
  522. onTap: () async {
  523. showFullImg(context, widget.msg);
  524. });
  525. }
  526. _videoMsg(BuildContext context, List<int> thumbnail) {
  527. var imgSize = _getImgSize();
  528. return InkWell(
  529. child: ClipRRect(
  530. child: Stack(
  531. alignment: Alignment.center,
  532. children: <Widget>[
  533. UploadImgItem(
  534. msg: widget.msg,
  535. cancelToken: _cancelToken,
  536. child: Container(
  537. width: imgSize.width,
  538. height: imgSize.height,
  539. child: Image(
  540. fit: BoxFit.contain,
  541. image: MemoryImage(Uint8List.fromList(thumbnail)),
  542. ),
  543. ))
  544. ],
  545. ),
  546. borderRadius: BorderRadius.circular(5),
  547. ),
  548. onTap: () {
  549. showVideoPage(context, widget.msg.localFile);
  550. },
  551. );
  552. }
  553. _msgLayout(BuildContext context, MsgModel msg) {
  554. Widget item;
  555. switch (ChatType.valueOf(msg.msgType)) {
  556. case ChatType.TextChatType:
  557. item = _textMsg(msg);
  558. break;
  559. case ChatType.EmoticonType:
  560. item = _textGif(msg.msgContent);
  561. break;
  562. case ChatType.ImageChatType:
  563. item = _imgMsg(msg.msgContent);
  564. break;
  565. case ChatType.ShortVideoChatType:
  566. item = _videoMsg(context, msg.msgContent);
  567. break;
  568. case ChatType.ShortVoiceChatType:
  569. item = _soundMsg();
  570. break;
  571. case ChatType.RedWalletChatType:
  572. item = RedBagItem(
  573. Key(msg.time.toString()), UserData().basicInfo.userId, msg);
  574. break;
  575. case ChatType.PlaceChatType:
  576. item = PlaceItem(isMe: true, placeContent: msg.msgContent);
  577. break;
  578. case ChatType.FileChatType:
  579. item = _fileMsgItem();
  580. break;
  581. default:
  582. }
  583. return wrapItemWithMenu(item);
  584. }
  585. Widget _fileMsgItem() {
  586. return UploadImgItem(
  587. msg: widget.msg,
  588. cancelToken: _cancelToken,
  589. child: Container(
  590. height: 100,
  591. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  592. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  593. decoration: BoxDecoration(
  594. color: isLongPressed ? Colors.grey[300] : SendMsgBg,
  595. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  596. child: FileMsgItem(widget.msg)));
  597. }
  598. Widget wrapItemWithMenu(item) {
  599. List<Function> actionsFunc = [];
  600. List<String> actions = [
  601. I18n.of(context).reply,
  602. I18n.of(context).delete,
  603. ];
  604. actionsFunc.add(() {
  605. print('发送引用的消息');
  606. MessageMgr().emit('Reply Select Message', widget.msg);
  607. });
  608. actionsFunc.add(() {
  609. MessageMgr().emit('Delete Select Message', widget.msg);
  610. });
  611. ///转发
  612. if (widget.msg.msgType == ChatType.TextChatType.value ||
  613. widget.msg.msgType == ChatType.ImageChatType.value ||
  614. widget.msg.msgType == ChatType.ShortVideoChatType.value ||
  615. widget.msg.msgType == ChatType.PlaceChatType.value ||
  616. widget.msg.msgType == ChatType.EmoticonType.value ||
  617. widget.msg.msgType == ChatType.FileChatType.value) {
  618. actions.add(I18n.of(context).forward);
  619. actionsFunc.add(() {
  620. print('转发消息');
  621. if (widget.msg.msgType == ChatType.FileChatType.value &&
  622. widget.msg.localFile == null) {
  623. showToast('请先下载文件');
  624. return;
  625. }
  626. AppNavigator.pushForwardPage(context, widget.msg);
  627. });
  628. }
  629. if (widget.msg.msgType == ChatType.FileChatType.value &&
  630. widget.msg.localFile != null) {
  631. //分享文件
  632. actions.add(I18n.of(context).copy_download_url);
  633. actionsFunc.add(() async {
  634. //如果是文件增加复制下载地址
  635. String path = widget.msg.localFile;
  636. UploadUtil().copyFileUrl(widget.msg, context);
  637. String type = 'file';
  638. if (path.contains('mp4') || path.contains('mp3')) {
  639. type = 'video';
  640. } else if (path.contains('png') ||
  641. path.contains('jpg') ||
  642. path.contains('jpeg') ||
  643. path.contains('JPG') ||
  644. path.contains('PNG')) {
  645. type = 'image';
  646. }
  647. ShareExtend.share(FileCacheMgr.replacePath(path), type);
  648. });
  649. }
  650. if (widget.msg.msgType == ChatType.TextChatType.value) {
  651. actions.insert(0, I18n.of(context).copy);
  652. actionsFunc.insert(0, () {
  653. //复制当前的文字
  654. print('复制文字 ${textList[curTextType]}');
  655. ClipboardData clipboardData =
  656. ClipboardData(text: textList[curTextType]);
  657. Clipboard.setData(clipboardData);
  658. });
  659. }
  660. if (widget.msg.msgType == ChatType.ShortVoiceChatType.value) {
  661. var soundPlayMode =
  662. Provider.of<KeyboardIndexProvider>(context).soundPlayMode;
  663. actions.add(soundPlayMode
  664. ? I18n.of(context).handset_playback
  665. : I18n.of(context).speaker_play);
  666. actionsFunc.add(() {
  667. Provider.of<KeyboardIndexProvider>(context)
  668. .changeSoundPlayMode(!soundPlayMode);
  669. SoundUtils.instance.savePlayModeConfig(soundPlayMode);
  670. });
  671. }
  672. // String date2 = DateTime.fromMillisecondsSinceEpoch(widget.msg.time).toString();
  673. bool isUrl = false;
  674. if (widget.msg.msgType == ChatType.TextChatType.value) {
  675. if (textList[curTextType].contains('http')) {
  676. isUrl = true;
  677. }
  678. }
  679. return WPopupMenu(
  680. child: item,
  681. actions: actions,
  682. onTap: () async {
  683. MessageMgr().emit('Keyboard Hide');
  684. if (isUrl) {
  685. if (await canLaunch(textList[curTextType])) {
  686. launch(textList[curTextType]);
  687. }
  688. }
  689. },
  690. onLongPressStart: () {
  691. isLongPressed = true;
  692. setState(() {});
  693. },
  694. onLongPressEnd: () {
  695. isLongPressed = false;
  696. setState(() {});
  697. },
  698. onValueChanged: (int value) {
  699. print('选择的是$value个菜单');
  700. if (value >= 0 && value < actionsFunc.length) {
  701. actionsFunc[value]();
  702. }
  703. },
  704. );
  705. }
  706. Widget _getSentMessageLayout(BuildContext context) {
  707. bool hasHeadImg = true;
  708. if (UserData().basicInfo.headimgurl == null ||
  709. UserData().basicInfo.headimgurl.length == 0) {
  710. hasHeadImg = false;
  711. }
  712. return Row(
  713. crossAxisAlignment: CrossAxisAlignment.start,
  714. mainAxisAlignment: MainAxisAlignment.end,
  715. children: <Widget>[
  716. MsgStateWidget(widget.msg),
  717. SizedBox(width: 3),
  718. _msgLayout(context, widget.msg),
  719. SizedBox(width: 10),
  720. Column(
  721. crossAxisAlignment: CrossAxisAlignment.end,
  722. children: <Widget>[
  723. ClipRRect(
  724. borderRadius: BorderRadius.circular(8),
  725. child: hasHeadImg
  726. ? CachedNetworkImage(
  727. imageUrl: UserData().basicInfo.headimgurl,
  728. placeholder: (context, url) => Image.asset(
  729. Constants.DefaultHeadImgUrl,
  730. width: 40,
  731. height: 40,
  732. ),
  733. width: 40,
  734. height: 40,
  735. )
  736. : SizedBox(
  737. width: 40,
  738. height: 40,
  739. child: Image.asset(R.assetsImagesDefaultNorAvatar))),
  740. ],
  741. )
  742. ]);
  743. }
  744. _receiveJIF(MsgModel msg) {
  745. var text = utf8.decode(msg.msgContent);
  746. return Container(
  747. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  748. child: extendedText(text,
  749. selectionEnabled: false, hideKeyboard: widget.hideKeyboard));
  750. }
  751. double _getTextWidth(String text, {double fontSize = FontSize}) {
  752. var tp = TextPainter(
  753. text: TextSpan(
  754. style: TextStyle(fontSize: fontSize), text: textList[curTextType]),
  755. textAlign: TextAlign.left,
  756. textDirection: TextDirection.ltr,
  757. textScaleFactor: 1,
  758. );
  759. tp.layout(maxWidth: maxWidth);
  760. if (text.contains('[')) {
  761. if (text.length < 5 && text.startsWith('[') && text.endsWith(']')) {
  762. ///单表情
  763. return 25;
  764. }
  765. int length = text.split('[').length;
  766. if (length > 1) {
  767. ///包含表情
  768. int scale = 6;
  769. if (length > 6) scale = 7;
  770. double width = tp.width + length * scale;
  771. return width > (maxWidth) ? maxWidth : width;
  772. }
  773. }
  774. return tp.width;
  775. ///单文字
  776. }
  777. blueDot(bool isShow) {
  778. return Container(
  779. margin: EdgeInsets.only(right: 5),
  780. decoration: BoxDecoration(
  781. shape: BoxShape.circle,
  782. color: isShow ? Color(0xFFFF7E00) : Color(0xFFCFCFCF),
  783. ),
  784. width: 4,
  785. height: 4,
  786. );
  787. }
  788. _receiveText(MsgModel msg) {
  789. List<Widget> showMsg = [];
  790. double width = 0.0;
  791. if (textList.length > 0) {
  792. bool isUrl = false;
  793. if (textList[curTextType].contains('http')) {
  794. isUrl = true;
  795. }
  796. if (msg.refMsgContent != null && msg.refMsgContent.length > 0) {
  797. var quoteItem = getQuoteItem(msg);
  798. width = getQuoteContentWidth(
  799. quoteItem['quoteMsg'],
  800. quoteItem['refName'],
  801. quoteItem['showTimeStr'],
  802. quoteItem['quoteContent']);
  803. showMsg.add(getQuoteContent(quoteItem['quoteMsg'], quoteItem['refName'],
  804. quoteItem['showTimeStr'], quoteItem['quoteContent'], false));
  805. }
  806. var contentWidth = _getTextWidth(textList[curTextType]);
  807. if (contentWidth > width && contentWidth <= maxWidth) {
  808. width = contentWidth;
  809. }
  810. showMsg.add(Container(
  811. constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
  812. alignment: Alignment.centerLeft,
  813. child: extendedText(
  814. textList[curTextType],
  815. color: isUrl ? Colors.blue : Constants.BlackTextColor,
  816. hideKeyboard: widget.hideKeyboard,
  817. fontSize: FontSize,
  818. )));
  819. }
  820. var minWidth = width + 20;
  821. if (msg.transTag != 0) {
  822. minWidth = 200;
  823. showMsg.add(Padding(
  824. padding: EdgeInsets.symmetric(vertical: 5),
  825. child: Divider(color: Color(0xFFECECEC), height: 1)));
  826. Widget tranWidget = _transProcessWidget(msg.transTag);
  827. showMsg.add(tranWidget);
  828. }
  829. Widget text = Stack(children: <Widget>[
  830. Container(
  831. width: width + 20,
  832. constraints:
  833. BoxConstraints(maxWidth: Screen.width - 120, minWidth: minWidth),
  834. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  835. child: Column(
  836. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  837. decoration: BoxDecoration(
  838. border: Border.all(color: ReciveBorderColor, width: 0.5),
  839. color: isLongPressed ? Colors.grey[300] : Colors.white,
  840. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  841. ),
  842. msg.transTag != 1 && msg.transTag != 0
  843. ? Positioned(
  844. right: 5,
  845. top: 5,
  846. child: Container(
  847. child: Row(children: <Widget>[
  848. blueDot(curTextType == 0),
  849. blueDot(curTextType == 1),
  850. blueDot(curTextType == 2),
  851. //blueDot(true),
  852. ])))
  853. : Container()
  854. ]);
  855. return InkWell(
  856. child: text,
  857. onTap: () {
  858. MessageMgr().emit('Keyboard Hide');
  859. if (msg.transTag == 1) {
  860. return;
  861. }
  862. if (msg.transTag == 2 || msg.transTag == 3) {
  863. setState(() {
  864. curTextType += 1;
  865. curTextType %= textList.length;
  866. });
  867. return;
  868. }
  869. },
  870. );
  871. }
  872. //用户评价人工翻译,差评
  873. rateTranslateResult() async {
  874. return await HttpUtil().rateTranslateResult(widget.msg, () {
  875. if (mounted) {
  876. setState(() {});
  877. }
  878. });
  879. }
  880. _translateItemWidget(int code, String title, Function onTap) {
  881. Color color = onTap == null ? Color(0xFFC5C5C5) : Color(0xFF6A6A6A);
  882. return InkWell(
  883. onTap: onTap,
  884. splashColor: Colors.red,
  885. child: Container(
  886. width: 80,
  887. child: Row(
  888. children: <Widget>[
  889. Icon(
  890. IconData(code, fontFamily: Constants.IconFontFamily),
  891. color: color,
  892. size: 20,
  893. ),
  894. SizedBox(width: 5),
  895. Expanded(
  896. child: SizedBox(
  897. child: Text(
  898. title,
  899. style: TextStyle(color: color, fontSize: 10),
  900. textScaleFactor: 1.0,
  901. maxLines: 1,
  902. overflow: TextOverflow.ellipsis,
  903. ),
  904. ))
  905. ],
  906. )));
  907. }
  908. bool isTranslating = false;
  909. _transProcessWidget(int transTag) {
  910. double width = 160;
  911. Widget userTranslateWidget;
  912. Widget machineTranslateWidget;
  913. if (transTag == 1) {
  914. //机器翻译中
  915. userTranslateWidget =
  916. _translateItemWidget(0xe670, I18n.of(context).man_retranslate, null);
  917. machineTranslateWidget =
  918. _translateItemWidget(0xe671, I18n.of(context).robotTranslate, null);
  919. } else if (transTag == 2) {
  920. //人工翻译中
  921. userTranslateWidget =
  922. _translateItemWidget(0xe670, I18n.of(context).ManTranslate, null);
  923. machineTranslateWidget = _translateItemWidget(
  924. 0xe671,
  925. I18n.of(context).robot_retranslate,
  926. textList.length <= 1
  927. ? null
  928. : () {
  929. setState(() {
  930. curTextType += 1;
  931. curTextType %= textList.length;
  932. });
  933. });
  934. } else if (transTag == 3) {
  935. //机器翻译完成
  936. userTranslateWidget = _translateItemWidget(
  937. 0xe670,
  938. I18n.of(context).man_retranslate,
  939. isTranslating
  940. ? null
  941. : () async {
  942. isTranslating = true;
  943. int money =
  944. Provider.of<MoneyChangeProvider>(context, listen: false)
  945. .money;
  946. int voucher =
  947. Provider.of<VoucherChangeProvider>(context, listen: false)
  948. .voucher;
  949. int needMoney = widget.msg.getNeedMoney();
  950. if (needMoney > voucher + money) {
  951. showToast('翻译券和H币不足');
  952. return;
  953. }
  954. var res = await HttpUtil().getPersonalTranslate(widget.msg);
  955. if (res) {
  956. print('请求人工翻译成功,进行扣费');
  957. setState(() {
  958. widget.msg.transTag = 2;
  959. //优先扣券
  960. if (voucher > 0) {
  961. int costQuan = min(voucher, needMoney);
  962. Provider.of<VoucherChangeProvider>(context,
  963. listen: false)
  964. .subVoucher(costQuan);
  965. }
  966. //不足的话再扣H币
  967. if (needMoney > voucher) {
  968. Provider.of<MoneyChangeProvider>(context, listen: false)
  969. .subMoney(needMoney - voucher);
  970. }
  971. });
  972. }
  973. });
  974. machineTranslateWidget = _translateItemWidget(
  975. 0xe671,
  976. I18n.of(context).robot_retranslate,
  977. textList.length <= 1
  978. ? null
  979. : () {
  980. setState(() {
  981. curTextType += 1;
  982. curTextType %= textList.length;
  983. });
  984. });
  985. } else if (transTag == 4 || transTag == 10) {
  986. //4人工翻译完成,未评论 10人工翻译完成已评论
  987. userTranslateWidget = InkWell(
  988. onTap: () {
  989. setState(() {
  990. curTextType = 0;
  991. });
  992. },
  993. child: Container(
  994. width: width / 2,
  995. child: Row(
  996. children: <Widget>[
  997. InkWell(
  998. child: Icon(
  999. IconData(0xe641, fontFamily: Constants.IconFontFamily),
  1000. size: 18,
  1001. color:
  1002. transTag == 10 ? Colors.grey : Color(0xFF087FF3)),
  1003. onTap: transTag == 10
  1004. ? null
  1005. : () {
  1006. CustomUI.showIosDialog(
  1007. context, I18n.of(context).bad_ev, () async {
  1008. bool isSuccess = await rateTranslateResult();
  1009. if (isSuccess) {
  1010. Navigator.of(context).pop(true);
  1011. showToast(I18n.of(context).success);
  1012. } else {
  1013. showToast(I18n.of(context).fail);
  1014. Navigator.of(context).pop();
  1015. }
  1016. }, () {
  1017. Navigator.of(context).pop();
  1018. });
  1019. },
  1020. ),
  1021. SizedBox(width: 5),
  1022. Expanded(
  1023. child: SizedBox(
  1024. child: Text(
  1025. I18n.of(context).over,
  1026. style: TextStyle(color: Color(0xFF087FF3), fontSize: 10),
  1027. textScaleFactor: 1.0,
  1028. maxLines: 1,
  1029. overflow: TextOverflow.ellipsis,
  1030. ),
  1031. ))
  1032. ],
  1033. )));
  1034. machineTranslateWidget =
  1035. _translateItemWidget(0xe675, I18n.of(context).see_original, () {
  1036. setState(() {
  1037. curTextType = textList.length - 1;
  1038. });
  1039. });
  1040. }
  1041. return Container(
  1042. height: 26,
  1043. alignment: Alignment.center,
  1044. child: Row(
  1045. children: <Widget>[
  1046. userTranslateWidget,
  1047. Expanded(
  1048. child: SizedBox(child: VerticalDivider(), height: 20, width: 2)),
  1049. machineTranslateWidget
  1050. ],
  1051. ),
  1052. );
  1053. }
  1054. _receiveImg(BuildContext context, List<int> imgData, {String downloadData}) {
  1055. // ImageProvider provider = MemoryImage(Uint8List.fromList(imgData));
  1056. ImageProvider provider = MemoryImage(widget.msg.localFile == null
  1057. ? Uint8List.fromList(imgData)
  1058. : File(widget.msg.localFile).readAsBytesSync());
  1059. var imgSize = _getImgSize();
  1060. return DownloadItem(
  1061. isAutoDown: false,
  1062. msg: widget.msg,
  1063. onFinishTap: () {
  1064. widget.hideKeyboard();
  1065. showFullImg(context, widget.msg);
  1066. },
  1067. child: Container(
  1068. alignment: Alignment.centerLeft,
  1069. width: imgSize.width,
  1070. height: imgSize.height,
  1071. child: ClipRRect(
  1072. child: Image(
  1073. image: provider ?? AssetImage(R.assetsImagesIcAlbum),
  1074. ),
  1075. borderRadius: BorderRadius.circular(5),
  1076. ),
  1077. ),
  1078. );
  1079. }
  1080. _receiveVideo(BuildContext context, List<int> imgData,
  1081. {String downloadData}) {
  1082. ImageProvider provider = MemoryImage(Uint8List.fromList(imgData));
  1083. var imgSize = _getImgSize();
  1084. return InkWell(
  1085. onTap: () {
  1086. if (widget.msg.localFile != null) {
  1087. showVideoPage(context, widget.msg.localFile);
  1088. }
  1089. },
  1090. child: DownloadItem(
  1091. isAutoDown: false,
  1092. msg: widget.msg,
  1093. child: Container(
  1094. width: imgSize.width,
  1095. height: imgSize.height,
  1096. child: ClipRRect(
  1097. child: Image(
  1098. image: provider ?? AssetImage(R.assetsImagesIcAlbum),
  1099. ),
  1100. borderRadius: BorderRadius.circular(5),
  1101. ),
  1102. ),
  1103. ));
  1104. }
  1105. showVideoPage(BuildContext context, String filePath) {
  1106. widget.hideKeyboard();
  1107. Navigator.push(context,
  1108. MaterialPageRoute<void>(builder: (BuildContext context) {
  1109. return VideoPage(videoPath: filePath);
  1110. }));
  1111. }
  1112. _receiveSound(BuildContext context, List<int> soundData) {
  1113. print(' build 收到的语音消息');
  1114. MsgModel msg = widget.msg;
  1115. var time = widget.msg.extraInfo / 1000;
  1116. if (time > 60) {
  1117. time = 60.0;
  1118. }
  1119. bool isPlaying = false;
  1120. if (curSoundUrl != null) {
  1121. isPlaying = SoundUtils().isPlaying(curSoundUrl);
  1122. }
  1123. var soundWidget = InkWell(
  1124. onTap: () async {
  1125. bool isLocal = true;
  1126. if (msg.localFile != null) {
  1127. isLocal = true;
  1128. curSoundUrl = msg.localFile;
  1129. } else {
  1130. isLocal = false;
  1131. var sessionId = msg.sessionId;
  1132. curSoundUrl = UploadUtil()
  1133. .getFullUrl(msg.extraFile, sessionId, msg.channelType);
  1134. }
  1135. print('当前文件$curSoundUrl 本地?$isLocal');
  1136. if (isPlaying) {
  1137. await SoundUtils().pause();
  1138. } else {
  1139. print('开始播放');
  1140. if (widget.msg.soundListened == 0) {
  1141. widget.msg.updateSoundListened();
  1142. }
  1143. await SoundUtils().play(curSoundUrl, isLocal: isLocal, onPlayed: () {
  1144. if (mounted) {
  1145. this.setState(() {});
  1146. }
  1147. }, complete: () {
  1148. if (mounted) {
  1149. this.setState(() {});
  1150. }
  1151. });
  1152. }
  1153. },
  1154. child: Container(
  1155. width: 130,
  1156. child: Row(children: <Widget>[
  1157. Container(
  1158. alignment: Alignment.center,
  1159. padding: EdgeInsets.only(bottom: 2),
  1160. margin: EdgeInsets.only(right: 10),
  1161. width: 25.5,
  1162. height: 25.5,
  1163. decoration: BoxDecoration(
  1164. border:
  1165. Border.all(color: const Color(0xFF1B92C7), width: 0.5),
  1166. color: const Color(0xFF04A4FE),
  1167. shape: BoxShape.circle),
  1168. child: Icon(
  1169. IconData(isPlaying ? 0xe652 : 0xe653,
  1170. fontFamily: Constants.IconFontFamily),
  1171. size: isPlaying ? 15 : 18,
  1172. color: Colors.white,
  1173. ),
  1174. ),
  1175. isPlaying
  1176. ? Stack(
  1177. children: <Widget>[
  1178. Container(
  1179. height: 18,
  1180. width: 19,
  1181. ),
  1182. Positioned(
  1183. bottom: 0,
  1184. child: VideoAnim(
  1185. begin: 18,
  1186. start: 0.444,
  1187. end: 4.5,
  1188. )),
  1189. Positioned(
  1190. left: 7,
  1191. bottom: 0,
  1192. child: VideoAnim(
  1193. begin: 4.5,
  1194. end: 18,
  1195. )),
  1196. Positioned(
  1197. left: 14,
  1198. bottom: 0,
  1199. child: VideoAnim(
  1200. begin: 18,
  1201. end: 4.5,
  1202. ))
  1203. ],
  1204. )
  1205. : Stack(
  1206. children: <Widget>[
  1207. Container(
  1208. height: 18,
  1209. width: 19,
  1210. ),
  1211. Positioned(
  1212. bottom: 0, child: CustomUI.buildAudioContaniner(12)),
  1213. Positioned(
  1214. left: 7,
  1215. bottom: 0,
  1216. child: CustomUI.buildAudioContaniner(4.5)),
  1217. Positioned(
  1218. left: 14,
  1219. bottom: 0,
  1220. child: CustomUI.buildAudioContaniner(18))
  1221. ],
  1222. ),
  1223. Expanded(child: SizedBox()),
  1224. fixedText(time.toStringAsFixed(0),
  1225. color: Constants.BlackTextColor, fontSize: 16)
  1226. ])),
  1227. );
  1228. List<Widget> showMsg = [];
  1229. showMsg.add(DownloadItem(
  1230. msg: widget.msg,
  1231. child: soundWidget,
  1232. isShowProgress: false,
  1233. ));
  1234. double width = 130;
  1235. double minWidth = 0;
  1236. if (textList.length > 0) {
  1237. width = _getTextWidth(textList[curTextType]) + 20;
  1238. width = min(width, Screen.width - 120);
  1239. minWidth = max(width, 150);
  1240. showMsg.add(Padding(
  1241. padding: EdgeInsets.symmetric(vertical: 5),
  1242. child: Divider(
  1243. height: 1,
  1244. )));
  1245. showMsg.add(Container(
  1246. child: extendedText(
  1247. textList[curTextType],
  1248. color: Constants.BlackTextColor,
  1249. hideKeyboard: widget.hideKeyboard,
  1250. fontSize: FontSize,
  1251. ),
  1252. alignment: Alignment.centerLeft,
  1253. constraints:
  1254. BoxConstraints(maxWidth: Screen.width - 120, minHeight: 22),
  1255. ));
  1256. }
  1257. if (msg.transTag != 0) {
  1258. minWidth = 200;
  1259. showMsg.add(Divider(color: Color(0xFFECECEC), height: 3));
  1260. Widget tranWidget = _transProcessWidget(msg.transTag);
  1261. showMsg.add(tranWidget);
  1262. }
  1263. return Container(
  1264. width: width + 20,
  1265. constraints:
  1266. msg.transTag != 0 ? BoxConstraints(minWidth: minWidth) : null,
  1267. child: Column(
  1268. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  1269. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  1270. decoration: BoxDecoration(
  1271. color: Colors.white,
  1272. border: Border.all(color: ReciveBorderColor, width: 0.5),
  1273. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  1274. );
  1275. }
  1276. void showFullImg(BuildContext context, MsgModel msg) {
  1277. print('显示图片');
  1278. Navigator.push(context,
  1279. MaterialPageRoute<void>(builder: (BuildContext context) {
  1280. return PhotoPage(msg: msg);
  1281. }));
  1282. }
  1283. _reveiveMsg(BuildContext context) {
  1284. Widget item;
  1285. switch (ChatType.valueOf(widget.msg.msgType)) {
  1286. case ChatType.TextChatType:
  1287. item = _receiveText(widget.msg);
  1288. break;
  1289. case ChatType.EmoticonType:
  1290. item = _receiveJIF(widget.msg);
  1291. break;
  1292. case ChatType.ImageChatType:
  1293. if (widget.msg.extraFile != null) {
  1294. item = _receiveImg(context, widget.msg.msgContent,
  1295. downloadData: widget.msg.extraFile);
  1296. } else {
  1297. item = _receiveImg(context, widget.msg.msgContent);
  1298. }
  1299. break;
  1300. case ChatType.ShortVideoChatType:
  1301. item = _receiveVideo(context, widget.msg.msgContent,
  1302. downloadData: widget.msg.extraFile);
  1303. break;
  1304. case ChatType.ShortVoiceChatType:
  1305. item = _receiveSound(context, widget.msg.msgContent);
  1306. break;
  1307. case ChatType.PlaceChatType:
  1308. item = PlaceItem(isMe: false, placeContent: widget.msg.msgContent);
  1309. break;
  1310. case ChatType.FileChatType:
  1311. item = _receiveFileMsgItem();
  1312. break;
  1313. default:
  1314. }
  1315. return wrapItemWithMenu(item);
  1316. }
  1317. Widget _receiveFileMsgItem() {
  1318. return DownloadItem(
  1319. isAutoDown: false,
  1320. msg: widget.msg,
  1321. onComplete: () {
  1322. if (mounted) {
  1323. setState(() {});
  1324. }
  1325. },
  1326. child: Container(
  1327. height: 100,
  1328. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  1329. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  1330. decoration: BoxDecoration(
  1331. color: Colors.white,
  1332. border: Border.all(color: ReciveBorderColor, width: 0.5),
  1333. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  1334. child: FileMsgItem(widget.msg)));
  1335. }
  1336. Widget _getReceivedMessageLayout(BuildContext context) {
  1337. bool hasHeadImg = true;
  1338. var memberModel = widget.memberModel;
  1339. if (memberModel == null) {
  1340. return Container();
  1341. }
  1342. if (memberModel.avtar == null || memberModel.avtar.length == 0) {
  1343. hasHeadImg = false;
  1344. }
  1345. GroupInfoModel infoModel = Provider.of<GroupInfoModel>(context);
  1346. var refName = Provider.of<RefNameProvider>(context)
  1347. .getGroupRefName(infoModel.sessionId, memberModel.memberId);
  1348. bool isShowSoundSate =
  1349. widget.msg.msgType == ChatType.ShortVoiceChatType.value &&
  1350. widget.msg.soundListened == 0;
  1351. return Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
  1352. Container(
  1353. margin: const EdgeInsets.only(right: 8.0),
  1354. child: GestureDetector(
  1355. child: ClipRRect(
  1356. borderRadius: BorderRadius.circular(8),
  1357. child: hasHeadImg
  1358. ? CachedNetworkImage(
  1359. imageUrl: memberModel.avtar,
  1360. placeholder: (context, url) => Image.asset(
  1361. Constants.DefaultHeadImgUrl,
  1362. width: 40,
  1363. height: 40,
  1364. ),
  1365. width: 40,
  1366. height: 40,
  1367. )
  1368. : SizedBox(
  1369. width: 40,
  1370. height: 40,
  1371. child: Image.asset(R.assetsImagesDefaultNorAvatar))),
  1372. onTap: () {
  1373. AppNavigator.pushProfileInfoPage(context, memberModel.memberId,
  1374. fromWhere: 2,
  1375. addMode: !FriendListMgr().isMyFriend(memberModel.memberId)
  1376. ? 1
  1377. : 0);
  1378. },
  1379. onLongPress: () {
  1380. print('long press user');
  1381. MessageMgr().emit('Alter User Message', memberModel);
  1382. },
  1383. )),
  1384. infoModel.isShowName > 0
  1385. ? Column(
  1386. crossAxisAlignment: CrossAxisAlignment.start,
  1387. children: <Widget>[
  1388. Container(
  1389. padding: EdgeInsets.only(left: 9),
  1390. child: fixedText(refName, fontSize: 12, color: Colors.grey),
  1391. ),
  1392. SizedBox(height: 2),
  1393. _reveiveMsg(context),
  1394. ],
  1395. )
  1396. : _reveiveMsg(context),
  1397. isShowSoundSate
  1398. ? Container(
  1399. margin: EdgeInsets.only(
  1400. left: 8, top: infoModel.isShowName > 0 ? 38 : 20),
  1401. child: CircleAvatar(
  1402. radius: 3.5,
  1403. backgroundColor: Colors.red,
  1404. ))
  1405. : Container()
  1406. ]);
  1407. }
  1408. }