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

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