Hibok
您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 
 
 
 

1542 行
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 = DateUtils()
  138. .getFormartData(timeSamp: sendTime, format: 'yyyy/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. _textMsg(MsgModel msgModel) {
  240. List<Widget> showMsg = [];
  241. var width = 0.0;
  242. var msg = utf8.decode(msgModel.msgContent);
  243. if (msg.contains('[ ')) {
  244. msg = msg.replaceAll('[ ', '[');
  245. }
  246. if (msg.contains(' ]')) {
  247. msg = msg.replaceAll(' ]', ']');
  248. }
  249. bool isUrl = false;
  250. if (textList[curTextType].contains('http')) {
  251. isUrl = true;
  252. }
  253. if (msgModel.refMsgContent != null && msgModel.refMsgContent.length > 0) {
  254. QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msgModel.refMsgContent);
  255. var refName = Provider.of<RefNameProvider>(context)
  256. .getGroupRefName(msgModel.sessionId, quoteMsg.sendUserId);
  257. var msgDate =
  258. DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt());
  259. var showTimeStr =
  260. getTodayTime(msgDate, sendTime: quoteMsg.sendTime.toInt());
  261. var timetWidth = CustomUI.getRealTextWidht(showTimeStr, 13);
  262. var nameWidhth = CustomUI.getRealTextWidht(refName, 13);
  263. width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 36;
  264. var tempIndex = quoteMsg.content.indexOf(':');
  265. var quoteContent = tempIndex == -1
  266. ? quoteMsg.content
  267. : quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2);
  268. var contentWidht = _getTextWidth(quoteContent, fontSize: 13);
  269. width = min(max(width, contentWidht), maxWidth);
  270. showMsg.add(InkWell(
  271. onTap: () {
  272. MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt());
  273. },
  274. child: Container(
  275. padding: EdgeInsets.all(8),
  276. margin: EdgeInsets.only(bottom: 5),
  277. decoration: BoxDecoration(
  278. color: Color(0xFFC4E0F5),
  279. borderRadius: BorderRadius.circular(5.5)),
  280. child: Column(
  281. crossAxisAlignment: CrossAxisAlignment.start,
  282. children: <Widget>[
  283. Row(children: <Widget>[
  284. Container(
  285. constraints: BoxConstraints(maxWidth: 70),
  286. child: Text(
  287. refName,
  288. style: TextStyle(fontSize: 13),
  289. overflow: TextOverflow.ellipsis,
  290. )),
  291. SizedBox(width: 20),
  292. Text(
  293. showTimeStr,
  294. style: TextStyle(fontSize: 13),
  295. )
  296. ]),
  297. SizedBox(height: 7.5),
  298. Text(
  299. quoteContent,
  300. style: TextStyle(fontSize: 13),
  301. )
  302. ],
  303. ),
  304. )));
  305. }
  306. var contentWidth = _getTextWidth(textList[curTextType]);
  307. if (contentWidth > width && contentWidth <= maxWidth) {
  308. width = contentWidth;
  309. }
  310. showMsg.add(Container(
  311. constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
  312. alignment: Alignment.centerLeft,
  313. child: extendedText(
  314. textList[curTextType],
  315. color: isUrl ? Colors.blue : Constants.BlackTextColor,
  316. hideKeyboard: widget.hideKeyboard,
  317. fontSize: FontSize,
  318. )));
  319. return Container(
  320. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  321. width: width + 20,
  322. child: Column(
  323. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  324. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  325. decoration: BoxDecoration(
  326. color: isLongPressed ? Colors.grey[300] : SendMsgBg,
  327. border: Border.all(color: Color(0xFFB9CBD7), width: 0.6),
  328. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  329. );
  330. }
  331. _soundMsg() {
  332. double time = widget.msg.extraInfo / 1000;
  333. if (time > 60) {
  334. time = 60.0;
  335. }
  336. bool isPlaying = false;
  337. var soundPath = widget.msg.localFile;
  338. isPlaying = SoundUtils().isPlaying(soundPath);
  339. var soundWidget = GestureDetector(
  340. child: Container(
  341. width: 120,
  342. child: Row(
  343. mainAxisAlignment: MainAxisAlignment.end,
  344. children: <Widget>[
  345. Container(
  346. alignment: Alignment.center,
  347. padding: EdgeInsets.only(bottom: 2),
  348. margin: EdgeInsets.only(right: 10),
  349. width: 25.5,
  350. height: 25.5,
  351. decoration: BoxDecoration(
  352. border:
  353. Border.all(color: const Color(0xFF1B92C7), width: 0.5),
  354. color: const Color(0xFF04A4FE),
  355. shape: BoxShape.circle),
  356. child: Icon(
  357. IconData(isPlaying ? 0xe652 : 0xe653,
  358. fontFamily: Constants.IconFontFamily),
  359. size: isPlaying ? 15 : 18,
  360. color: Colors.white,
  361. ),
  362. ),
  363. isPlaying
  364. ? Stack(
  365. children: <Widget>[
  366. Container(
  367. height: 18,
  368. width: 19,
  369. ),
  370. Positioned(
  371. bottom: 0,
  372. child: VideoAnim(
  373. begin: 18,
  374. start: 0.444,
  375. end: 4.5,
  376. )),
  377. Positioned(
  378. left: 7,
  379. bottom: 0,
  380. child: VideoAnim(
  381. begin: 4.5,
  382. end: 18,
  383. )),
  384. Positioned(
  385. left: 14,
  386. bottom: 0,
  387. child: VideoAnim(
  388. begin: 18,
  389. end: 4.5,
  390. ))
  391. ],
  392. )
  393. : Stack(
  394. children: <Widget>[
  395. Container(
  396. height: 18,
  397. width: 19,
  398. ),
  399. Positioned(
  400. bottom: 0, child: CustomUI.buildAudioContaniner(12)),
  401. Positioned(
  402. left: 7,
  403. bottom: 0,
  404. child: CustomUI.buildAudioContaniner(4.5)),
  405. Positioned(
  406. left: 14,
  407. bottom: 0,
  408. child: CustomUI.buildAudioContaniner(18))
  409. ],
  410. ),
  411. Expanded(child: SizedBox()),
  412. fixedText(time.toStringAsFixed(0), color: SendMsgText, fontSize: 16)
  413. ],
  414. ),
  415. padding: EdgeInsets.symmetric(horizontal: 15, vertical: 12),
  416. decoration: BoxDecoration(
  417. color: SendMsgBg,
  418. border: Border.all(color: Color(0xFFB9CBD7), width: 0.6),
  419. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  420. ),
  421. onTap: () async {
  422. print('播放状态 : $isPlaying');
  423. print('当前文件$soundPath ');
  424. if (isPlaying) {
  425. SoundUtils().pause();
  426. } else {
  427. SoundUtils().play(soundPath, onPlayed: () {
  428. if (mounted) {
  429. setState(() {});
  430. }
  431. }, complete: () {
  432. if (mounted) {
  433. setState(() {});
  434. }
  435. });
  436. }
  437. },
  438. );
  439. return UploadImgItem(
  440. msg: widget.msg,
  441. child: soundWidget,
  442. isShowProgress: false,
  443. );
  444. }
  445. Size _getImgSize() {
  446. double aspectRatio = widget.msg.extraInfo / 100;
  447. var maxWidth = Screen.width * 0.65;
  448. var maxHeight = Screen.height / 4;
  449. var width, height;
  450. if (maxWidth / maxHeight > aspectRatio) {
  451. height = maxHeight;
  452. width = maxHeight * aspectRatio;
  453. } else {
  454. width = maxWidth;
  455. height = maxWidth / aspectRatio;
  456. }
  457. return Size(width, height);
  458. }
  459. _imgMsg(List<int> imgData) {
  460. var imgSize = _getImgSize();
  461. ImageProvider provider = MemoryImage(widget.msg.localFile == null
  462. ? Uint8List.fromList(imgData)
  463. : File(widget.msg.localFile).readAsBytesSync());
  464. return GestureDetector(
  465. child: ClipRRect(
  466. child: UploadImgItem(
  467. msg: widget.msg,
  468. cancelToken: _cancelToken,
  469. child: Container(
  470. height: imgSize.height,
  471. width: imgSize.width,
  472. child: Image(
  473. fit: BoxFit.contain,
  474. image: provider,
  475. ),
  476. )),
  477. borderRadius: BorderRadius.circular(5),
  478. ),
  479. onTap: () async {
  480. showFullImg(context, widget.msg);
  481. });
  482. }
  483. _videoMsg(BuildContext context, List<int> thumbnail) {
  484. var imgSize = _getImgSize();
  485. return InkWell(
  486. child: ClipRRect(
  487. child: Stack(
  488. alignment: Alignment.center,
  489. children: <Widget>[
  490. UploadImgItem(
  491. msg: widget.msg,
  492. cancelToken: _cancelToken,
  493. child: Container(
  494. width: imgSize.width,
  495. height: imgSize.height,
  496. child: Image(
  497. fit: BoxFit.contain,
  498. image: MemoryImage(Uint8List.fromList(thumbnail)),
  499. ),
  500. ))
  501. ],
  502. ),
  503. borderRadius: BorderRadius.circular(5),
  504. ),
  505. onTap: () {
  506. showVideoPage(context, widget.msg.localFile);
  507. },
  508. );
  509. }
  510. _msgLayout(BuildContext context, MsgModel msg) {
  511. Widget item;
  512. switch (ChatType.valueOf(msg.msgType)) {
  513. case ChatType.TextChatType:
  514. item = _textMsg(msg);
  515. break;
  516. case ChatType.EmoticonType:
  517. item = _textGif(msg.msgContent);
  518. break;
  519. case ChatType.ImageChatType:
  520. item = _imgMsg(msg.msgContent);
  521. break;
  522. case ChatType.ShortVideoChatType:
  523. item = _videoMsg(context, msg.msgContent);
  524. break;
  525. case ChatType.ShortVoiceChatType:
  526. item = _soundMsg();
  527. break;
  528. case ChatType.RedWalletChatType:
  529. item = RedBagItem(
  530. Key(msg.time.toString()), UserData().basicInfo.userId, msg);
  531. break;
  532. case ChatType.PlaceChatType:
  533. item = PlaceItem(isMe: true, placeContent: msg.msgContent);
  534. break;
  535. case ChatType.FileChatType:
  536. item = _fileMsgItem();
  537. break;
  538. default:
  539. }
  540. return wrapItemWithMenu(item);
  541. }
  542. Widget _fileMsgItem() {
  543. return UploadImgItem(
  544. msg: widget.msg,
  545. cancelToken: _cancelToken,
  546. child: Container(
  547. height: 100,
  548. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  549. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  550. decoration: BoxDecoration(
  551. color: isLongPressed ? Colors.grey[300] : SendMsgBg,
  552. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  553. child: FileMsgItem(widget.msg)));
  554. }
  555. Widget wrapItemWithMenu(item) {
  556. List<Function> actionsFunc = [];
  557. List<String> actions = [
  558. I18n.of(context).reply,
  559. I18n.of(context).delete,
  560. ];
  561. actionsFunc.add(() {
  562. print('发送引用的消息');
  563. MessageMgr().emit('Reply Select Message', widget.msg);
  564. });
  565. actionsFunc.add(() {
  566. MessageMgr().emit('Delete Select Message', widget.msg);
  567. });
  568. ///转发
  569. if (widget.msg.msgType == ChatType.TextChatType.value ||
  570. widget.msg.msgType == ChatType.ImageChatType.value ||
  571. widget.msg.msgType == ChatType.ShortVideoChatType.value ||
  572. widget.msg.msgType == ChatType.PlaceChatType.value ||
  573. widget.msg.msgType == ChatType.EmoticonType.value ||
  574. widget.msg.msgType == ChatType.FileChatType.value) {
  575. actions.add(I18n.of(context).forward);
  576. actionsFunc.add(() {
  577. print('转发消息');
  578. if (widget.msg.msgType == ChatType.FileChatType.value &&
  579. widget.msg.localFile == null) {
  580. showToast('请先下载文件');
  581. return;
  582. }
  583. AppNavigator.pushForwardPage(context, widget.msg);
  584. });
  585. }
  586. if (widget.msg.msgType == ChatType.FileChatType.value &&
  587. widget.msg.localFile != null) {
  588. //分享文件
  589. actions.add(I18n.of(context).copy_download_url);
  590. actionsFunc.add(() async {
  591. //如果是文件增加复制下载地址
  592. String path = widget.msg.localFile;
  593. UploadUtil().copyFileUrl(widget.msg, context);
  594. String type = 'file';
  595. if (path.contains('mp4') || path.contains('mp3')) {
  596. type = 'video';
  597. } else if (path.contains('png') ||
  598. path.contains('jpg') ||
  599. path.contains('jpeg') ||
  600. path.contains('JPG') ||
  601. path.contains('PNG')) {
  602. type = 'image';
  603. }
  604. ShareExtend.share(FileCacheMgr.replacePath(path), type);
  605. });
  606. }
  607. if (widget.msg.msgType == ChatType.TextChatType.value) {
  608. actions.insert(0, I18n.of(context).copy);
  609. actionsFunc.insert(0, () {
  610. //复制当前的文字
  611. print('复制文字 ${textList[curTextType]}');
  612. ClipboardData clipboardData =
  613. ClipboardData(text: textList[curTextType]);
  614. Clipboard.setData(clipboardData);
  615. });
  616. }
  617. if (widget.msg.msgType == ChatType.ShortVoiceChatType.value) {
  618. var soundPlayMode =
  619. Provider.of<KeyboardIndexProvider>(context).soundPlayMode;
  620. actions.add(soundPlayMode
  621. ? I18n.of(context).handset_playback
  622. : I18n.of(context).speaker_play);
  623. actionsFunc.add(() {
  624. Provider.of<KeyboardIndexProvider>(context)
  625. .changeSoundPlayMode(!soundPlayMode);
  626. SoundUtils.instance.savePlayModeConfig(soundPlayMode);
  627. });
  628. }
  629. // String date2 = DateTime.fromMillisecondsSinceEpoch(widget.msg.time).toString();
  630. bool isUrl = false;
  631. if (widget.msg.msgType == ChatType.TextChatType.value) {
  632. if (textList[curTextType].contains('http')) {
  633. isUrl = true;
  634. }
  635. }
  636. return WPopupMenu(
  637. child: item,
  638. actions: actions,
  639. onTap: () async {
  640. MessageMgr().emit('Keyboard Hide');
  641. if (isUrl) {
  642. if (await canLaunch(textList[curTextType])) {
  643. launch(textList[curTextType]);
  644. }
  645. }
  646. },
  647. onLongPressStart: () {
  648. isLongPressed = true;
  649. setState(() {});
  650. },
  651. onLongPressEnd: () {
  652. isLongPressed = false;
  653. setState(() {});
  654. },
  655. onValueChanged: (int value) {
  656. print('选择的是$value个菜单');
  657. if (value >= 0 && value < actionsFunc.length) {
  658. actionsFunc[value]();
  659. }
  660. },
  661. );
  662. }
  663. Widget _getSentMessageLayout(BuildContext context) {
  664. bool hasHeadImg = true;
  665. if (UserData().basicInfo.headimgurl == null ||
  666. UserData().basicInfo.headimgurl.length == 0) {
  667. hasHeadImg = false;
  668. }
  669. return Row(
  670. crossAxisAlignment: CrossAxisAlignment.start,
  671. mainAxisAlignment: MainAxisAlignment.end,
  672. children: <Widget>[
  673. MsgStateWidget(widget.msg),
  674. SizedBox(width: 3),
  675. _msgLayout(context, widget.msg),
  676. SizedBox(width: 10),
  677. Column(
  678. crossAxisAlignment: CrossAxisAlignment.end,
  679. children: <Widget>[
  680. ClipRRect(
  681. borderRadius: BorderRadius.circular(8),
  682. child: hasHeadImg
  683. ? CachedNetworkImage(
  684. imageUrl: UserData().basicInfo.headimgurl,
  685. placeholder: (context, url) => Image.asset(
  686. Constants.DefaultHeadImgUrl,
  687. width: 40,
  688. height: 40,
  689. ),
  690. width: 40,
  691. height: 40,
  692. )
  693. : SizedBox(
  694. width: 40,
  695. height: 40,
  696. child: Image.asset(R.assetsImagesDefaultNorAvatar))),
  697. ],
  698. )
  699. ]);
  700. }
  701. _receiveJIF(MsgModel msg) {
  702. var text = utf8.decode(msg.msgContent);
  703. return Container(
  704. constraints: BoxConstraints(maxWidth: Screen.width - 120),
  705. child: extendedText(text,
  706. selectionEnabled: false, hideKeyboard: widget.hideKeyboard));
  707. }
  708. double _getTextWidth(String text, {double fontSize = FontSize}) {
  709. var tp = TextPainter(
  710. text: TextSpan(
  711. style: TextStyle(fontSize: fontSize), text: textList[curTextType]),
  712. textAlign: TextAlign.left,
  713. textDirection: TextDirection.ltr,
  714. textScaleFactor: 1,
  715. );
  716. tp.layout(maxWidth: maxWidth);
  717. if (text.contains('[')) {
  718. if (text.length < 5 && text.startsWith('[') && text.endsWith(']')) {
  719. ///单表情
  720. return 25;
  721. }
  722. int length = text.split('[').length;
  723. if (length > 1) {
  724. ///包含表情
  725. int scale = 6;
  726. if (length > 6) scale = 7;
  727. double width = tp.width + length * scale;
  728. return width > (maxWidth) ? maxWidth : width;
  729. }
  730. }
  731. return tp.width;
  732. ///单文字
  733. }
  734. blueDot(bool isShow) {
  735. return Container(
  736. margin: EdgeInsets.only(right: 5),
  737. decoration: BoxDecoration(
  738. shape: BoxShape.circle,
  739. color: isShow ? Color(0xFFFF7E00) : Color(0xFFCFCFCF),
  740. ),
  741. width: 6,
  742. height: 6,
  743. );
  744. }
  745. _receiveText(MsgModel msg) {
  746. List<Widget> showMsg = [];
  747. double width = 0.0;
  748. if (textList.length > 0) {
  749. bool isUrl = false;
  750. if (textList[curTextType].contains('http')) {
  751. isUrl = true;
  752. }
  753. if (msg.refMsgContent != null && msg.refMsgContent.length > 0) {
  754. QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msg.refMsgContent);
  755. var refName = Provider.of<RefNameProvider>(context)
  756. .getGroupRefName(msg.sessionId, quoteMsg.sendUserId);
  757. var msgDate =
  758. DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt());
  759. var showTimeStr =
  760. getTodayTime(msgDate, sendTime: quoteMsg.sendTime.toInt());
  761. var timetWidth = CustomUI.getRealTextWidht(showTimeStr, 13);
  762. var nameWidhth = CustomUI.getRealTextWidht(refName, 13);
  763. width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 36;
  764. var quoteContent =
  765. quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2);
  766. var contentWidht = _getTextWidth(quoteContent, fontSize: 13);
  767. width = min(max(width, contentWidht), maxWidth);
  768. showMsg.add(InkWell(
  769. onTap: () {
  770. MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt());
  771. },
  772. child: Container(
  773. padding: EdgeInsets.all(8),
  774. margin: EdgeInsets.only(bottom: 5),
  775. decoration: BoxDecoration(
  776. color: Color(0xFFC4E0F5),
  777. borderRadius: BorderRadius.circular(5.5)),
  778. child: Column(
  779. crossAxisAlignment: CrossAxisAlignment.start,
  780. children: <Widget>[
  781. Row(children: <Widget>[
  782. Container(
  783. constraints: BoxConstraints(maxWidth: 70),
  784. child: Text(
  785. refName,
  786. style: TextStyle(fontSize: 13),
  787. overflow: TextOverflow.ellipsis,
  788. )),
  789. SizedBox(width: 20),
  790. Text(
  791. showTimeStr,
  792. style: TextStyle(fontSize: 13),
  793. )
  794. ]),
  795. SizedBox(height: 7.5),
  796. Text(
  797. quoteContent,
  798. style: TextStyle(fontSize: 13),
  799. )
  800. ],
  801. ),
  802. )));
  803. }
  804. var contentWidth = _getTextWidth(textList[curTextType]);
  805. if (contentWidth > width && contentWidth <= maxWidth) {
  806. width = contentWidth;
  807. }
  808. showMsg.add(InkWell(
  809. onTap: () {
  810. if (msg.transTag == 1) {
  811. return;
  812. }
  813. if (msg.transTag == 2 || msg.transTag == 3) {
  814. setState(() {
  815. curTextType += 1;
  816. curTextType %= textList.length;
  817. });
  818. return;
  819. }
  820. },
  821. child: Container(
  822. constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22),
  823. alignment: Alignment.centerLeft,
  824. child: extendedText(
  825. textList[curTextType],
  826. color: isUrl ? Colors.blue : Constants.BlackTextColor,
  827. hideKeyboard: widget.hideKeyboard,
  828. fontSize: FontSize,
  829. ))));
  830. }
  831. var minWidth = width + 20;
  832. if (msg.transTag != 0) {
  833. minWidth = 200;
  834. showMsg.add(Padding(
  835. padding: EdgeInsets.symmetric(vertical: 5),
  836. child: Divider(color: Color(0xFFECECEC), height: 1)));
  837. Widget tranWidget = _transProcessWidget(msg.transTag);
  838. showMsg.add(tranWidget);
  839. }
  840. Widget text = Stack(children: <Widget>[
  841. Container(
  842. width: width + 20,
  843. constraints:
  844. BoxConstraints(maxWidth: Screen.width - 120, minWidth: minWidth),
  845. padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5),
  846. child: Column(
  847. crossAxisAlignment: CrossAxisAlignment.start, children: showMsg),
  848. decoration: BoxDecoration(
  849. border: Border.all(color: ReciveBorderColor, width: 0.5),
  850. color: isLongPressed ? Colors.grey[300] : Colors.white,
  851. borderRadius: BorderRadius.all(Radius.circular(ChatRadius))),
  852. ),
  853. msg.transTag != 1 && msg.transTag != 0
  854. ? Positioned(
  855. right: 5,
  856. top: 5,
  857. child: Container(
  858. child: Row(children: <Widget>[
  859. blueDot(curTextType == 0),
  860. blueDot(curTextType == 1),
  861. blueDot(curTextType == 2),
  862. //blueDot(true),
  863. ])))
  864. : Container()
  865. ]);
  866. return text;
  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 ? Constants.GreyTextColor : Color(0xFF087FF3);
  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. }