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

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