From 672df2fbc5e920429806cc955d2ed3b93b24e9d4 Mon Sep 17 00:00:00 2001 From: KerwinZheng <772112648@qq.com> Date: Tue, 31 Mar 2020 14:55:43 +0800 Subject: [PATCH] 1 --- lib/chat/ChatPage.dart | 95 +++-- lib/chat/ChatPageItem.dart | 380 +++++++++++------- lib/chat/company_server_view.dart | 3 - lib/chat/group_chat_item.dart | 53 ++- lib/chat/group_chat_view.dart | 31 +- lib/chat/input_bar.dart | 48 +-- lib/chat/translate_state.dart | 1 - lib/data/translate_hk_data_mgr.dart | 12 +- lib/home/AddProgram.dart | 3 - lib/home/InformUser.dart | 3 - lib/home/ProfilePage.dart | 3 - lib/home/homeMain.dart | 2 - .../translation_butler_page.dart | 14 - .../translation_evaluation_dialog.dart | 3 - lib/utils/CustomUI.dart | 24 +- lib/utils/HttpUtil.dart | 1 - lib/utils/count_down_button.dart | 5 +- lib/utils/file_cache_mgr.dart | 1 - lib/utils/image_util.dart | 1 - lib/utils/msgHandler.dart | 4 +- lib/utils/screen_shot.dart | 1 - lib/utils/white_opacity_anim.dart | 52 +++ 22 files changed, 437 insertions(+), 303 deletions(-) create mode 100644 lib/utils/white_opacity_anim.dart diff --git a/lib/chat/ChatPage.dart b/lib/chat/ChatPage.dart index 7e1f554..e2df0cf 100644 --- a/lib/chat/ChatPage.dart +++ b/lib/chat/ChatPage.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:chat/home/audio_chat_view.dart'; import 'package:chat/utils/screen.dart'; import 'package:chat/utils/upload_util.dart'; +import 'package:chat/utils/white_opacity_anim.dart'; import 'package:fixnum/fixnum.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:chat/chat/translate_state.dart'; @@ -35,9 +36,9 @@ import 'package:dio/dio.dart'; import 'package:extended_text/extended_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:oktoast/oktoast.dart'; import 'package:provider/provider.dart'; +import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../r.dart'; import 'ChatPageItem.dart'; import 'input_bar.dart'; @@ -62,7 +63,10 @@ class ChatPage extends StatefulWidget { } class _ChatPageState extends State { - ScrollController _scrollCtrl = ScrollController(); + final ItemScrollController itemScrollController = ItemScrollController(); + final ItemPositionsListener itemPositionListener = + ItemPositionsListener.create(); + //ScrollController _scrollCtrl = ScrollController(); MessageMgr msgMgr = MessageMgr(); @@ -77,6 +81,8 @@ class _ChatPageState extends State { //统计聊天时长 int startTime; + int jumpTime; + @override void dispose() { var endTime = DateTime.now().millisecondsSinceEpoch ~/ 1000; @@ -86,15 +92,36 @@ class _ChatPageState extends State { msgMgr.off('New Chat Message', receiveMsg); msgMgr.off('Keyboard Hide', dealWithKeyboardHide); msgMgr.off('Delete Select Message', _deleteItem); + msgMgr.off('Jump to Msg', jumpToMsg); MsgHandler.curActiveSession = 0; SoundUtils().stop(); nickNameController.dispose(); - _scrollCtrl.dispose(); - super.dispose(); } + jumpToMsg(time) { + //var screenItemNums = itemPositionListener.itemPositions.value.length; + int jumIndex = 0; + jumpTime = time; + for (int i = 0; i < msgList.length; i++) { + if (time == msgList[i].time) { + jumIndex = i - 1; // - screenItemNums + 2; + break; + } + } + if (jumIndex < 0) { + jumIndex = 0; + } + if (jumIndex > msgList.length - 1) { + jumIndex = msgList.length - 1; + } + setState(() { + itemScrollController.scrollTo( + index: jumIndex, duration: new Duration(microseconds: 1)); + }); + } + @override void initState() { super.initState(); @@ -110,6 +137,7 @@ class _ChatPageState extends State { msgMgr.on('Keyboard Hide', dealWithKeyboardHide); msgMgr.on('Send CoinBag', _sendCoin); msgMgr.on('Delete Select Message', _deleteItem); + msgMgr.on('Jump to Msg', jumpToMsg); } void _sendFile(File file) async { @@ -366,7 +394,10 @@ class _ChatPageState extends State { ? _buildTranslationButler() : Container(), Expanded(child: _buildMessageList()), - InputBar(sendMsg: sendMsg,isTranslateHK: widget.isTranslateButler,), + InputBar( + sendMsg: sendMsg, + isTranslateHK: widget.isTranslateButler, + ), ], ))), behavior: HitTestBehavior.translucent, @@ -475,7 +506,7 @@ class _ChatPageState extends State { return Container(); } - Widget button = Container( + Widget button = Container( key: mykey, color: Colors.blue, width: 60, @@ -485,14 +516,13 @@ class _ChatPageState extends State { return GestureDetector( onHorizontalDragUpdate: dragEvent, onVerticalDragUpdate: dragEvent, - onTap: (){ + onTap: () { setState(() { isShowAudio = !isShowAudio; isShowZoomButton = !isShowZoomButton; }); }, child: Container( - child: Transform.translate( offset: Offset(dx, dy), child: Align( @@ -585,7 +615,6 @@ class _ChatPageState extends State { ); } - Widget _buildMessageList() { return Container( alignment: Alignment.topCenter, @@ -600,13 +629,15 @@ class _ChatPageState extends State { )) : NotificationListener( child: Scrollbar( - child: ListView.builder( - reverse: true, - shrinkWrap: true, + child: ScrollablePositionedList.builder( + physics: new ClampingScrollPhysics(), itemCount: msgList.length, - controller: _scrollCtrl, - padding: EdgeInsets.all(8.0), itemBuilder: _buildItem, + itemScrollController: itemScrollController, + itemPositionsListener: itemPositionListener, + //padding: EdgeInsets.all(8.0), + reverse: true, + hitCallback: hideKeyBoard, )), onNotification: (notification) { if (notification is ScrollNotification) { @@ -628,7 +659,6 @@ class _ChatPageState extends State { } sendMsg(MsgModel msg) { - // if(widget.isTranslateButler){ ///翻译管家聊天通道 // msg.channelType = ChatChannelType.TransHK.value; // } @@ -648,12 +678,8 @@ class _ChatPageState extends State { MsgHandler.sendChatMsg(msg); if (mounted) { setState(() {}); - if (_scrollCtrl.hasClients) { - _scrollCtrl.animateTo(0, - duration: new Duration(milliseconds: 500), curve: Curves.ease); - } + itemScrollController.jumpTo(index: 0); } -// testBig(msg); } MsgModel msg; @@ -677,10 +703,6 @@ class _ChatPageState extends State { void receiveMsg(args) { if (mounted) { setState(() {}); - if (_scrollCtrl.hasClients) { - _scrollCtrl.animateTo(0, - duration: new Duration(milliseconds: 500), curve: Curves.ease); - } } } @@ -699,11 +721,26 @@ class _ChatPageState extends State { } MsgModel msg = msgList[index]; - return ChatPageItem( + if (msg.time == jumpTime) { + return WhiteOpacityAnim( key: Key(msg.time.toString()), - msg: msg, - hideKeyboard: readOnly, - friendInfo: friendInfo, - lastMsgTime: lastMsgTime); + child: ChatPageItem( + key: Key(msg.time.toString()), + msg: msg, + hideKeyboard: readOnly, + friendInfo: friendInfo, + lastMsgTime: lastMsgTime), + animFinishCallback: () { + jumpTime = null; + }, + ); + } else { + return ChatPageItem( + key: Key(msg.time.toString()), + msg: msg, + hideKeyboard: readOnly, + friendInfo: friendInfo, + lastMsgTime: lastMsgTime); + } } } diff --git a/lib/chat/ChatPageItem.dart b/lib/chat/ChatPageItem.dart index a6b9b52..3d501a3 100644 --- a/lib/chat/ChatPageItem.dart +++ b/lib/chat/ChatPageItem.dart @@ -90,6 +90,8 @@ class _ChatPageItemState extends State CancelToken _cancelToken = CancelToken(); bool isLongPressed = false; + + double maxWidth = Screen.width - 140; @override void initState() { super.initState(); @@ -146,10 +148,10 @@ class _ChatPageItemState extends State } } - getTodayTime(msgDate) { + getTodayTime(msgDate, {var sendTime}) { String showTimeStr; - var sendTime = widget.msg.time; + sendTime = sendTime ?? widget.msg.time; var today = DateTime.now(); //今天 if (msgDate.year == today.year && @@ -188,7 +190,7 @@ class _ChatPageItemState extends State return Container( width: Screen.width, - margin: const EdgeInsets.symmetric(vertical: 10.0), + margin: const EdgeInsets.symmetric(vertical: 18.0,horizontal: 8), child: Column( children: [ showTime == null @@ -259,16 +261,18 @@ class _ChatPageItemState extends State ///todo 翻译管家系统通知消息 print('这里应该要有翻译管家'); - if (type == ChatType.GroupChatNoticeType.value && widget.msg.channelType ==ChatChannelType.Session.value) { - TransHKChatNotice res = TransHKChatNotice.fromBuffer(widget.msg.msgContent); + if (type == ChatType.GroupChatNoticeType.value && + widget.msg.channelType == ChatChannelType.Session.value) { + TransHKChatNotice res = + TransHKChatNotice.fromBuffer(widget.msg.msgContent); - if(res.noticeType==TransHKChatNoticeType.StartChat){ + if (res.noticeType == TransHKChatNoticeType.StartChat) { ///开始翻译服务 return _buildServiceCard(true, () {}); - }else if(res.noticeType==TransHKChatNoticeType.EndChat){ + } else if (res.noticeType == TransHKChatNoticeType.EndChat) { ///翻译服务结束 return _buildServiceCard(false, () {}); - }else{ + } else { return Container(); } // return Container(); @@ -293,8 +297,6 @@ class _ChatPageItemState extends State // } // } - - } return Container(); } @@ -313,55 +315,100 @@ class _ChatPageItemState extends State } _textMsg(List msgContent) { + List showMsg = []; + var width = 0.0; var msg = utf8.decode(msgContent); - bool isUrl =false; - if(textList[curTextType].contains('http') ){ - isUrl =true; + if (msg.contains('[ ')) { + msg = msg.replaceAll('[ ', '['); + } + if (msg.contains(' ]')) { + msg = msg.replaceAll(' ]', ']'); + } + bool isUrl = false; + if (textList[curTextType].contains('http')) { + isUrl = true; + } + + if (widget.msg.refMsgContent != null && + widget.msg.refMsgContent.length > 0) { + QuoteMsg quoteMsg = QuoteMsg.fromBuffer(widget.msg.refMsgContent); + var refName = Provider.of(context) + .getRefName(friendInfo.userId, friendInfo.nickName); + var msgDate = + DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt()); + var showTimeStr = getTodayTime(msgDate, sendTime: quoteMsg.sendTime.toInt()); + + var timetWidth = CustomUI.getRealTextWidht(showTimeStr, 13); + var nameWidhth = CustomUI.getRealTextWidht(refName, 13); + width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 36; + var tempIndex = quoteMsg.content.indexOf(':'); + var quoteContent = tempIndex == -1 + ? quoteMsg.content + : quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2); + var contentWidht = _getTextWidth(quoteContent, fontSize: 13); + width = min(max(width, contentWidht), maxWidth); + showMsg.add(InkWell( + onTap: () { + MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt()); + }, + child: Container( + padding: EdgeInsets.all(8), + margin: EdgeInsets.only(bottom: 5), + decoration: BoxDecoration( + color: Color(0xFFC4E0F5), + borderRadius: BorderRadius.circular(5.5)), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row(children: [ + Container( + constraints: BoxConstraints(maxWidth: 70), + child: Text( + refName, + style: TextStyle(fontSize: 13), + overflow: TextOverflow.ellipsis, + )), + SizedBox(width: 20), + Text( + showTimeStr, + style: TextStyle(fontSize: 13), + ) + ]), + SizedBox(height: 7.5), + Text( + quoteContent, + style: TextStyle(fontSize: 13), + ) + ], + ), + ))); + } + var contentWidth = _getTextWidth(textList[curTextType]); + if (contentWidth > width && contentWidth <= maxWidth) { + width = contentWidth; } - Widget text = Container( + + showMsg.add(Container( + constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22), + alignment: Alignment.centerLeft, + child: extendedText( + textList[curTextType], + color: isUrl ? Colors.blue : Constants.BlackTextColor, + hideKeyboard: widget.hideKeyboard, + fontSize: FontSize, + ))); + + return Container( constraints: BoxConstraints(maxWidth: Screen.width - 120), - child: extendedText( - msg, - hideKeyboard: widget.hideKeyboard, - fontSize: FontSize, - color: isUrl?Colors.blue:Colors.black, - ), + width: width + 20, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: showMsg), padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5), decoration: BoxDecoration( color: isLongPressed ? Colors.grey[300] : SendMsgBg, border: Border.all(color: Color(0xFFB9CBD7), width: 0.6), borderRadius: BorderRadius.all(Radius.circular(ChatRadius))), ); - - if (widget.msg.refMsgContent != null && - widget.msg.refMsgContent.length > 0) { - QuoteMsg quoteMsg = QuoteMsg.fromBuffer(widget.msg.refMsgContent); - - return Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - text, - SizedBox(height: 2), - Container( - constraints: BoxConstraints(maxWidth: Screen.width - 120), - padding: EdgeInsets.symmetric(vertical: 1, horizontal: 3), - child: Text( - quoteMsg.content, - maxLines: 1, - textScaleFactor: 1.0, - overflow: TextOverflow.ellipsis, - style: TextStyle(fontSize: 12), - ), - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(5)), - ) - ], - ); - } else { - return text; - } } _soundMsg() { @@ -504,7 +551,9 @@ class _ChatPageItemState extends State _imgMsg(List imgData) { var imgSize = _getImgSize(); - ImageProvider provider = MemoryImage(widget.msg.localFile==null?Uint8List.fromList(imgData):File(widget.msg.localFile).readAsBytesSync()); + ImageProvider provider = MemoryImage(widget.msg.localFile == null + ? Uint8List.fromList(imgData) + : File(widget.msg.localFile).readAsBytesSync()); return GestureDetector( child: ClipRRect( @@ -651,7 +700,6 @@ class _ChatPageItemState extends State List actions = [ I18n.of(context).delete, I18n.of(context).reply, - ]; actionsFunc.add(() { @@ -662,53 +710,48 @@ class _ChatPageItemState extends State MessageMgr().emit('Reply Select Message', widget.msg); }); - ///转发 - if (widget.msg.msgType == ChatType.TextChatType.value|| - widget.msg.msgType == ChatType.ImageChatType.value|| - widget.msg.msgType == ChatType.ShortVideoChatType.value|| - widget.msg.msgType == ChatType.PlaceChatType.value|| - widget.msg.msgType == ChatType.EmoticonType.value|| - widget.msg.msgType == ChatType.FileChatType.value - ){ - actions.add( I18n.of(context).forward); + if (widget.msg.msgType == ChatType.TextChatType.value || + widget.msg.msgType == ChatType.ImageChatType.value || + widget.msg.msgType == ChatType.ShortVideoChatType.value || + widget.msg.msgType == ChatType.PlaceChatType.value || + widget.msg.msgType == ChatType.EmoticonType.value || + widget.msg.msgType == ChatType.FileChatType.value) { + actions.add(I18n.of(context).forward); actionsFunc.add(() { print('转发消息'); - if(widget.msg.msgType == ChatType.FileChatType.value && widget.msg.localFile==null){ + if (widget.msg.msgType == ChatType.FileChatType.value && + widget.msg.localFile == null) { showToast('请先下载文件'); - return ; + return; } AppNavigator.pushForwardPage(context, widget.msg); }); } - - - - if (widget.msg.msgType == ChatType.FileChatType.value &&widget.msg.localFile!=null) { - - - + if (widget.msg.msgType == ChatType.FileChatType.value && + widget.msg.localFile != null) { //分享文件 actions.add(I18n.of(context).copy_download_url); - actionsFunc.add(() async{ + actionsFunc.add(() async { UploadUtil().copyFileUrl(widget.msg, context); String path = widget.msg.localFile; - String type='file'; - if(path.contains('mp4') ||path.contains('mp3')){ + String type = 'file'; + if (path.contains('mp4') || path.contains('mp3')) { type = 'video'; - }else if(path.contains('png')||path.contains('jpg')||path.contains('jpeg')||path.contains('JPG')||path.contains('PNG')){ + } else if (path.contains('png') || + path.contains('jpg') || + path.contains('jpeg') || + path.contains('JPG') || + path.contains('PNG')) { type = 'image'; } ShareExtend.share(FileCacheMgr.replacePath(path), type); - - }); - } if (widget.msg.msgType == ChatType.TextChatType.value) { @@ -736,18 +779,17 @@ class _ChatPageItemState extends State }); } // String date2 = DateTime.fromMillisecondsSinceEpoch(widget.msg.time).toString(); - bool isUrl =false; - if(widget.msg.msgType==ChatType.TextChatType.value ){ - if( textList[curTextType].contains('http')){ - isUrl =true; + bool isUrl = false; + if (widget.msg.msgType == ChatType.TextChatType.value) { + if (textList[curTextType].contains('http')) { + isUrl = true; } - } - return WPopupMenu( + return WPopupMenu( child: item, actions: actions, - onTap: ()async{ - if(isUrl){ + onTap: () async { + if (isUrl) { if (await canLaunch(textList[curTextType])) { launch(textList[curTextType]); } @@ -784,9 +826,9 @@ class _ChatPageItemState extends State return extendedText(text, hideKeyboard: widget.hideKeyboard); } - double _getTextWidth(String text) { + double _getTextWidth(String text, {double fontSize: FontSize}) { var tp = TextPainter( - text: TextSpan(style: TextStyle(fontSize: FontSize), text: text), + text: TextSpan(style: TextStyle(fontSize: fontSize), text: text), textAlign: TextAlign.left, textDirection: TextDirection.ltr, textScaleFactor: 1, @@ -813,11 +855,70 @@ class _ChatPageItemState extends State _receiveText(MsgModel msg) { List showMsg = []; + double width = 0.0; if (textList.length > 0) { + bool isUrl = false; + if (textList[curTextType].contains('http')) { + isUrl = true; + } + + if (msg.refMsgContent != null && msg.refMsgContent.length > 0) { + QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msg.refMsgContent); + + var refName = Provider.of(context) + .getGroupRefName(msg.sessionId, quoteMsg.sendUserId); - bool isUrl =false; - if(textList[curTextType].contains('http') ){ - isUrl =true; + var msgDate = + DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt()); + var showTimeStr = getTodayTime(msgDate, sendTime: quoteMsg.sendTime.toInt()); + + var timetWidth = CustomUI.getRealTextWidht(showTimeStr, 13); + var nameWidhth = CustomUI.getRealTextWidht(refName, 13); + width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 36; + var quoteContent = + quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2); + var contentWidht = _getTextWidth(quoteContent, fontSize: 13); + width = min(max(width, contentWidht), maxWidth); + showMsg.add(InkWell( + onTap: () { + MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt()); + }, + child: Container( + padding: EdgeInsets.all(8), + margin: EdgeInsets.only(bottom: 5), + decoration: BoxDecoration( + color: Color(0xFFC4E0F5), + borderRadius: BorderRadius.circular(5.5)), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row(children: [ + Container( + constraints: BoxConstraints(maxWidth: 70), + child: Text( + refName, + style: TextStyle(fontSize: 13), + overflow: TextOverflow.ellipsis, + )), + SizedBox(width: 20), + Text( + showTimeStr, + style: TextStyle(fontSize: 13), + ) + ]), + SizedBox(height: 7.5), + Text( + quoteContent, + style: TextStyle(fontSize: 13), + ) + ], + ), + ))); + } + + var contentWidth = _getTextWidth(textList[curTextType]); + if (contentWidth > width && contentWidth <= maxWidth) { + width = contentWidth; } showMsg.add(InkWell( @@ -834,8 +935,7 @@ class _ChatPageItemState extends State } }, child: Container( - constraints: - BoxConstraints(maxWidth: Screen.width - 140, minHeight: 22), + constraints: BoxConstraints(maxWidth: maxWidth, minHeight: 22), alignment: Alignment.centerLeft, child: extendedText( textList[curTextType], @@ -845,9 +945,7 @@ class _ChatPageItemState extends State )))); } - var width = _getTextWidth(textList[curTextType]); - - var minWidth = width; + var minWidth = width + 20; if (msg.transTag != 0) { minWidth = 200; showMsg.add(Padding( @@ -857,7 +955,6 @@ class _ChatPageItemState extends State showMsg.add(tranWidget); } - ///todo Widget text = Stack(children: [ Container( width: width + 20, @@ -871,7 +968,7 @@ class _ChatPageItemState extends State color: isLongPressed ? Colors.grey[300] : Colors.white, borderRadius: BorderRadius.all(Radius.circular(ChatRadius))), ), - msg.transTag != 1 + msg.transTag != 1 && msg.transTag != 0 ? Positioned( right: 5, top: 5, @@ -885,34 +982,7 @@ class _ChatPageItemState extends State : Container() ]); - if (msg.refMsgContent != null && msg.refMsgContent.length > 0) { - QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msg.refMsgContent); - - return Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - text, - SizedBox(height: 2), - Container( - constraints: BoxConstraints(maxWidth: Screen.width - 120), - padding: EdgeInsets.symmetric(vertical: 1, horizontal: 3), - child: Text( - quoteMsg.content, - maxLines: 1, - textScaleFactor: 1.0, - overflow: TextOverflow.ellipsis, - style: TextStyle(fontSize: 12), - ), - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(5)), - ) - ], - ); - } else { - return text; - } + return text; } _translateItemWidget(int code, String title, Function onTap) { @@ -950,14 +1020,17 @@ class _ChatPageItemState extends State if (transTag == 1) { //机器翻译中 - userTranslateWidget = _translateItemWidget(0xe670, I18n.of(context).man_retranslate, null); + userTranslateWidget = + _translateItemWidget(0xe670, I18n.of(context).man_retranslate, null); machineTranslateWidget = _translateItemWidget(0xe671, I18n.of(context).robotTranslate, null); } else if (transTag == 2) { //人工翻译中 - userTranslateWidget = _translateItemWidget(0xe670, I18n.of(context).ManTranslate, null); - machineTranslateWidget = _translateItemWidget(0xe671, I18n.of(context).robot_retranslate, () { + userTranslateWidget = + _translateItemWidget(0xe670, I18n.of(context).ManTranslate, null); + machineTranslateWidget = + _translateItemWidget(0xe671, I18n.of(context).robot_retranslate, () { setState(() { curTextType += 1; curTextType %= textList.length; @@ -1009,7 +1082,8 @@ class _ChatPageItemState extends State }); } }); - machineTranslateWidget = _translateItemWidget(0xe671, I18n.of(context).robot_retranslate, () { + machineTranslateWidget = + _translateItemWidget(0xe671, I18n.of(context).robot_retranslate, () { setState(() { curTextType += 1; curTextType %= textList.length; @@ -1064,7 +1138,8 @@ class _ChatPageItemState extends State )) ], ))); - machineTranslateWidget = _translateItemWidget(0xe675, I18n.of(context).see_original, () { + machineTranslateWidget = + _translateItemWidget(0xe675, I18n.of(context).see_original, () { setState(() { curTextType = textList.length - 1; }); @@ -1086,15 +1161,16 @@ class _ChatPageItemState extends State } _receiveImg(BuildContext context, List imgData, {String downloadData}) { - - ImageProvider provider = MemoryImage(widget.msg.localFile==null?Uint8List.fromList(imgData):File(widget.msg.localFile).readAsBytesSync()); + ImageProvider provider = MemoryImage(widget.msg.localFile == null + ? Uint8List.fromList(imgData) + : File(widget.msg.localFile).readAsBytesSync()); var imgSize = _getImgSize(); return DownloadItem( isAutoDown: false, msg: widget.msg, - onFinishTap: (){ + onFinishTap: () { widget.hideKeyboard(); showFullImg(context, widget.msg); }, @@ -1109,7 +1185,6 @@ class _ChatPageItemState extends State ), ), ); - } _receiveVideo(BuildContext context, List imgData, @@ -1459,10 +1534,8 @@ class _ChatPageItemState extends State ]); } - Widget _buildServiceCard(bool isStart, Function callBack) { return Container( - alignment: Alignment.center, margin: EdgeInsets.all(10), child: Card( @@ -1500,28 +1573,27 @@ class _ChatPageItemState extends State isStart ? Container() : Expanded( - child: Container( - margin: EdgeInsets.only(left: 15), - height: 30, - child: RaisedButton( - color: Color(0xff3875E9), - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.all(Radius.circular(10))), - child: Text( - I18n.of(context).translation_butler_evaluation, - textScaleFactor: 1.0, - style: TextStyle(color: Colors.white, fontSize: 15), - ), - onPressed: () { - CustomUI.buildTranslationEvaluationDialog(context); - }), - )), + child: Container( + margin: EdgeInsets.only(left: 15), + height: 30, + child: RaisedButton( + color: Color(0xff3875E9), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.all(Radius.circular(10))), + child: Text( + I18n.of(context).translation_butler_evaluation, + textScaleFactor: 1.0, + style: TextStyle(color: Colors.white, fontSize: 15), + ), + onPressed: () { + CustomUI.buildTranslationEvaluationDialog(context); + }), + )), ], ), ), ), ); } - } diff --git a/lib/chat/company_server_view.dart b/lib/chat/company_server_view.dart index f1bf89a..8de0f58 100644 --- a/lib/chat/company_server_view.dart +++ b/lib/chat/company_server_view.dart @@ -7,8 +7,6 @@ import 'package:chat/data/constants.dart'; import 'package:chat/generated/i18n.dart'; import 'package:chat/models/ChatMsg.dart'; import 'package:chat/models/UserInfo.dart'; -import 'package:chat/photo/entity/options.dart'; -import 'package:chat/photo/photo.dart'; import 'package:chat/proto/chat.pb.dart'; import 'package:chat/r.dart'; import 'package:chat/utils/CustomUI.dart'; @@ -23,7 +21,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:multi_image_picker/multi_image_picker.dart'; import 'package:oktoast/oktoast.dart'; -import 'package:photo_manager/photo_manager.dart'; import 'package:chat/utils/MessageMgr.dart'; class CompanyServerPage extends StatefulWidget { diff --git a/lib/chat/group_chat_item.dart b/lib/chat/group_chat_item.dart index d548976..99252c0 100644 --- a/lib/chat/group_chat_item.dart +++ b/lib/chat/group_chat_item.dart @@ -36,7 +36,6 @@ import 'package:chat/utils/video_anim.dart'; import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:provider/provider.dart'; import 'package:oktoast/oktoast.dart'; import 'package:chat/utils/HttpUtil.dart'; @@ -147,10 +146,10 @@ class _GroupChatPageItemState extends State } } - getTodayTime(msgDate) { + getTodayTime(msgDate, {var sendTime}) { String showTimeStr; - var sendTime = widget.msg.time; + sendTime = sendTime ?? widget.msg.time; var today = DateTime.now(); //今天 if (msgDate.year == today.year && @@ -189,6 +188,7 @@ class _GroupChatPageItemState extends State return Container( width: Screen.width, + color: Colors.white.withOpacity(0), margin: const EdgeInsets.symmetric(vertical: 10.0), child: Column( children: [ @@ -301,14 +301,19 @@ class _GroupChatPageItemState extends State var msgDate = DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt()); - var showTimeStr = getTodayTime(msgDate); + var showTimeStr = + getTodayTime(msgDate, sendTime: quoteMsg.sendTime.toInt()); - var timetWidth = _getRealTextWidht(showTimeStr, fontSize: 13); - var nameWidhth = _getRealTextWidht(refName, fontSize: 13); + var timetWidth = CustomUI.getRealTextWidht(showTimeStr, 13); + var nameWidhth = CustomUI.getRealTextWidht(refName, 13); width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 36; - if (width > maxWidth) { - width = maxWidth; - } + var tempIndex = quoteMsg.content.indexOf(':'); + var quoteContent = tempIndex == -1 + ? quoteMsg.content + : quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2); + var contentWidht = _getTextWidth(quoteContent, fontSize: 13); + width = min(max(width, contentWidht), maxWidth); + showMsg.add(InkWell( onTap: () { MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt()); @@ -338,7 +343,7 @@ class _GroupChatPageItemState extends State ]), SizedBox(height: 7.5), Text( - quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2), + quoteContent, style: TextStyle(fontSize: 13), ) ], @@ -778,17 +783,6 @@ class _GroupChatPageItemState extends State selectionEnabled: false, hideKeyboard: widget.hideKeyboard)); } - double _getRealTextWidht(String text, {double fontSize = FontSize}) { - TextPainter _textPainter = TextPainter( - maxLines: 2, - text: TextSpan( - text: text, - style: TextStyle(fontSize: fontSize, color: Colors.black)), - textDirection: TextDirection.ltr) - ..layout(); - return _textPainter.width; - } - double _getTextWidth(String text, {double fontSize = FontSize}) { var tp = TextPainter( text: TextSpan( @@ -850,14 +844,16 @@ class _GroupChatPageItemState extends State var msgDate = DateTime.fromMillisecondsSinceEpoch(quoteMsg.sendTime.toInt()); - var showTimeStr = getTodayTime(msgDate); + var showTimeStr = + getTodayTime(msgDate, sendTime: quoteMsg.sendTime.toInt()); - var timetWidth = _getRealTextWidht(showTimeStr, fontSize: 13); - var nameWidhth = _getRealTextWidht(refName, fontSize: 13); + var timetWidth = CustomUI.getRealTextWidht(showTimeStr, 13); + var nameWidhth = CustomUI.getRealTextWidht(refName, 13); width = timetWidth + (nameWidhth > 70 ? 70 : nameWidhth) + 36; - if (width > maxWidth) { - width = maxWidth; - } + var quoteContent = + quoteMsg.content.substring(quoteMsg.content.indexOf(':') + 2); + var contentWidht = _getTextWidth(quoteContent, fontSize: 13); + width = min(max(width, contentWidht), maxWidth); showMsg.add(InkWell( onTap: () { MessageMgr().emit('Jump to Msg', quoteMsg.sendTime.toInt()); @@ -887,8 +883,7 @@ class _GroupChatPageItemState extends State ]), SizedBox(height: 7.5), Text( - quoteMsg.content - .substring(quoteMsg.content.indexOf(':') + 2), + quoteContent, style: TextStyle(fontSize: 13), ) ], diff --git a/lib/chat/group_chat_view.dart b/lib/chat/group_chat_view.dart index ac3288e..5cceb18 100644 --- a/lib/chat/group_chat_view.dart +++ b/lib/chat/group_chat_view.dart @@ -24,6 +24,7 @@ import 'package:chat/utils/sound_util.dart'; import 'package:chat/utils/sp_utils.dart'; import 'package:chat/utils/sql_util.dart'; import 'package:chat/utils/upload_util.dart'; +import 'package:chat/utils/white_opacity_anim.dart'; import 'package:extended_text/extended_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -75,6 +76,8 @@ class _GroupChatPageState extends State { String alterUserName = ''; + int jumpTime; + @override void dispose() { var endTime = DateTime.now().millisecondsSinceEpoch ~/ 1000; @@ -160,11 +163,12 @@ class _GroupChatPageState extends State { } jumpToMsg(time) { - var screenItemNums = itemPositionListener.itemPositions.value.length; + //var screenItemNums = itemPositionListener.itemPositions.value.length; + jumpTime = time; int jumIndex = 0; for (int i = 0; i < msgList.length; i++) { if (time == msgList[i].time) { - jumIndex = i - screenItemNums + 2; + jumIndex = i - 1; // - screenItemNums + 2; break; } } @@ -174,7 +178,8 @@ class _GroupChatPageState extends State { if (jumIndex > msgList.length - 1) { jumIndex = msgList.length - 1; } - itemScrollController.jumpTo(index: jumIndex); + itemScrollController.scrollTo( + index: jumIndex, duration: new Duration(microseconds: 1)); } void _sendFile(File file) async { @@ -516,9 +521,10 @@ class _GroupChatPageState extends State { MsgHandler.insertMsgToDB(msg); MsgHandler.sendChatMsg(msg); if (mounted) { - setState(() {}); + setState(() { + itemScrollController.jumpTo(index: 0); + }); } - itemScrollController.jumpTo(index: 0); } MsgModel msg; @@ -564,18 +570,29 @@ class _GroupChatPageState extends State { } MsgModel msg = msgList[index]; + var result; if (msg.from == 0) { - return GroupChatPageItem( + result = GroupChatPageItem( key: Key(msg.time.toString()), msg: msg, lastMsgTime: lastMsgTime); } else { - return GroupChatPageItem( + result = GroupChatPageItem( key: Key(msg.time.toString()), msg: msg, memberModel: widget.groupInfoModel.getMember(msg.from), hideKeyboard: readOnly, lastMsgTime: lastMsgTime); } + if (msg.time == jumpTime) { + result = WhiteOpacityAnim( + key: Key(msg.time.toString()), + child: result, + animFinishCallback: () { + jumpTime = null; + }, + ); + } + return result; } quiteGroup() { diff --git a/lib/chat/input_bar.dart b/lib/chat/input_bar.dart index ee4ff1a..1c731be 100644 --- a/lib/chat/input_bar.dart +++ b/lib/chat/input_bar.dart @@ -2,9 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; -import 'package:chat/chat/ChatPageItem.dart'; import 'package:chat/chat/keyboard_icon.dart'; -import 'package:chat/chat/my_extended_text_selection_controls.dart'; import 'package:chat/chat/record_view.dart'; import 'package:chat/chat/util_keyboard.dart'; import 'package:chat/data/UserData.dart'; @@ -14,8 +12,6 @@ import 'package:chat/home/alter_select_view.dart'; import 'package:chat/models/ChatMsg.dart'; import 'package:chat/models/group_info_model.dart'; import 'package:chat/models/keyboard_provider.dart'; -import 'package:chat/photo/entity/options.dart'; -import 'package:chat/photo/photo.dart'; import 'package:chat/proto/all.pbserver.dart'; import 'package:chat/utils/CustomUI.dart'; import 'package:chat/utils/MessageMgr.dart'; @@ -26,24 +22,21 @@ import 'package:chat/utils/keyboard_utils.dart'; import 'package:chat/utils/msgHandler.dart'; import 'package:chat/utils/screen.dart'; import 'package:chat/utils/sound_util.dart'; -import 'package:extended_text_field/extended_text_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:multi_image_picker/multi_image_picker.dart'; import 'package:oktoast/oktoast.dart'; -import 'package:photo_manager/photo_manager.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'emoji_gif_text.dart'; import 'emoji_text.dart'; -import 'my_special_text_span_builder.dart'; class InputBar extends StatefulWidget { final Function sendMsg; final bool isTranslateHK; - InputBar({this.sendMsg,this.isTranslateHK=false}); + InputBar({this.sendMsg, this.isTranslateHK = false}); @override InputBarState createState() => InputBarState(); @@ -161,7 +154,7 @@ class InputBarState extends State // SystemChannels.textInput.invokeMethod('TextInput.show'); } - _getRefShortText() { + _getRefShortText(){ if (refMsg == null) { return null; } @@ -217,11 +210,19 @@ class InputBarState extends State break; default: } - - GroupInfoModel groupInfoModel = Provider.of(context); - var member = groupInfoModel.getMember(refMsg.from); - - return '${member.refName}: $desc'; + if (refMsg.channelType == ChatChannelType.Group.value) { + GroupInfoModel groupInfoModel = Provider.of(context); + var member = groupInfoModel.getMember(refMsg.from); + return '${member.refName}: $desc'; + //} + //else if (refMsg.channelType == ChatChannelType.Session.value) { + // UserInfo info = await HttpUtil().getFriendInfo(refMsg.from); + // var refName = Provider.of(context) + // .getRefName(info.userId, info.nickName); + // return '$refName: $desc'; + } else { + return desc; + } } bool isReceiver = false; @@ -237,8 +238,7 @@ class InputBarState extends State Widget centerWidget; Widget input = Container( - child: - TextField( + child: TextField( // textSelectionControls: ExtendedMaterialTextSelectionControls(), keyboardAppearance: Brightness.light, onChanged: (String messageText) { @@ -708,17 +708,16 @@ class InputBarState extends State for (var i = 0; i < resultList.length; i++) { Asset photoEntity = resultList[i]; ByteData byteData = await photoEntity.getByteData(); - File file = await FileCacheMgr().writeFile('temp-photo-${DateTime.now().millisecondsSinceEpoch}-${photoEntity.name}', byteData.buffer.asInt8List(0)); + File file = await FileCacheMgr().writeFile( + 'temp-photo-${DateTime.now().millisecondsSinceEpoch}-${photoEntity.name}', + byteData.buffer.asInt8List(0)); _sendPhotoFile(file); } } - - } on Exception catch (e) { - print(e.toString()); + print(e.toString()); } - // var photos = await PhotoPicker.pickAsset( // context: context, // themeColor: Color(0xFFF0F0F0), @@ -767,7 +766,7 @@ class InputBarState extends State if (imgSize > ImgSizeLimit) { print('图片大于 $ImgSizeLimit,压缩'); //发送压缩图 WidgetUtil.getCompressImg(path,quality: 80,percentage: 80); - sendImg = await WidgetUtil.getCompressImg(imgFile.absolute.path ); + sendImg = await WidgetUtil.getCompressImg(imgFile.absolute.path); isNeedUpload = true; } else { sendImg = imgFile.readAsBytesSync(); @@ -841,8 +840,9 @@ class InputBarState extends State } } - ChatChannelType channelType =isGroup ? ChatChannelType.Group : ChatChannelType.Session; - if(widget.isTranslateHK){ + ChatChannelType channelType = + isGroup ? ChatChannelType.Group : ChatChannelType.Session; + if (widget.isTranslateHK) { channelType = ChatChannelType.TransHK; print('聊天是 TransHK'); } diff --git a/lib/chat/translate_state.dart b/lib/chat/translate_state.dart index 29a6018..64dacaa 100644 --- a/lib/chat/translate_state.dart +++ b/lib/chat/translate_state.dart @@ -3,7 +3,6 @@ import 'package:chat/data/constants.dart'; import 'package:chat/generated/i18n.dart'; import 'package:chat/utils/HttpUtil.dart'; import 'package:chat/utils/MessageMgr.dart'; -import 'package:chat/utils/msgHandler.dart'; import 'package:chat/utils/screen.dart'; import 'package:flutter/material.dart'; import 'package:oktoast/oktoast.dart'; diff --git a/lib/data/translate_hk_data_mgr.dart b/lib/data/translate_hk_data_mgr.dart index b1e0b31..9b3570f 100644 --- a/lib/data/translate_hk_data_mgr.dart +++ b/lib/data/translate_hk_data_mgr.dart @@ -1,14 +1,4 @@ -import 'dart:convert'; - -import 'package:chat/data/UserData.dart'; -import 'package:chat/data/chat_data_mgr.dart'; -import 'package:chat/models/group_info_model.dart'; -import 'package:chat/proto/chat.pbserver.dart'; -import 'package:chat/utils/MessageMgr.dart'; -import 'package:chat/utils/group_member_model.dart'; -import 'package:chat/utils/sql_util.dart'; -import 'package:chat/utils/upload_util.dart'; -import 'package:crclib/crclib.dart'; + class TranslateOrder{ diff --git a/lib/home/AddProgram.dart b/lib/home/AddProgram.dart index b153722..1ec8966 100644 --- a/lib/home/AddProgram.dart +++ b/lib/home/AddProgram.dart @@ -12,8 +12,6 @@ import 'package:chat/home/SelectPage.dart'; import 'package:chat/home/VerificationCenter.dart'; import 'package:chat/home/VipPage.dart'; import 'package:chat/models/money_change.dart'; -import 'package:chat/photo/entity/options.dart'; -import 'package:chat/photo/photo.dart'; import 'package:chat/utils/ChargeMoney.dart'; import 'package:chat/utils/CustomUI.dart'; import 'package:chat/utils/HttpUtil.dart'; @@ -31,7 +29,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:multi_image_picker/multi_image_picker.dart'; import 'package:oktoast/oktoast.dart'; -import 'package:photo_manager/photo_manager.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../utils/ShadowButton.dart'; diff --git a/lib/home/InformUser.dart b/lib/home/InformUser.dart index 6f8c9d5..8dbc889 100644 --- a/lib/home/InformUser.dart +++ b/lib/home/InformUser.dart @@ -6,8 +6,6 @@ import 'package:chat/data/UserData.dart'; import 'package:chat/data/WebData.dart'; import 'package:chat/data/constants.dart'; import 'package:chat/generated/i18n.dart'; -import 'package:chat/photo/entity/options.dart'; -import 'package:chat/photo/photo.dart'; import 'package:chat/utils/CustomUI.dart'; import 'package:chat/utils/HttpUtil.dart'; import 'package:chat/utils/PicSwiper.dart'; @@ -18,7 +16,6 @@ import 'package:flutter/material.dart'; import 'package:multi_image_picker/multi_image_picker.dart'; import 'package:oktoast/oktoast.dart'; -import 'package:photo_manager/photo_manager.dart'; import '../data/UserData.dart'; import '../utils/TokenMgr.dart'; diff --git a/lib/home/ProfilePage.dart b/lib/home/ProfilePage.dart index 8c0e770..3d96bfa 100644 --- a/lib/home/ProfilePage.dart +++ b/lib/home/ProfilePage.dart @@ -6,8 +6,6 @@ import 'package:chat/home/rich_title.dart'; import 'package:chat/models/money_change.dart'; import 'package:chat/models/ref_name_provider.dart'; import 'package:chat/models/voucher_change.dart'; -import 'package:chat/photo/entity/options.dart'; -import 'package:chat/photo/photo.dart'; import 'package:chat/utils/ChargeMoney.dart'; import 'package:chat/utils/app_navigator.dart'; import 'package:chat/utils/blacklist_mgr.dart'; @@ -42,7 +40,6 @@ import 'package:image_picker/image_picker.dart'; import 'package:multi_image_picker/multi_image_picker.dart'; import 'package:oktoast/oktoast.dart'; import 'package:permission_handler/permission_handler.dart'; -import 'package:photo_manager/photo_manager.dart'; import 'package:provider/provider.dart'; import 'package:share/share.dart'; import '../utils/FullWithButton.dart'; diff --git a/lib/home/homeMain.dart b/lib/home/homeMain.dart index 506ea8f..c197457 100644 --- a/lib/home/homeMain.dart +++ b/lib/home/homeMain.dart @@ -9,7 +9,6 @@ import 'package:chat/home/realtimehelper/real_time_helper_page.dart'; import 'package:chat/home/unread_dot_widget.dart'; import 'package:chat/models/UserInfo.dart'; import 'package:chat/models/ref_name_provider.dart'; -import 'package:chat/proto/transhousekeeper.pb.dart'; import 'package:chat/utils/CustomUI.dart'; import 'package:chat/utils/HttpUtil.dart'; import 'package:chat/utils/MessageMgr.dart'; @@ -34,7 +33,6 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:chat/utils/my_bottom_navigation_bar.dart' as myBottm; import 'friend_page.dart'; -import 'group_chat_page.dart'; class NavigationIconView { final BottomNavigationBarItem item; diff --git a/lib/home/realtimehelper/translation_butler_page.dart b/lib/home/realtimehelper/translation_butler_page.dart index 043e5d3..b4180d3 100644 --- a/lib/home/realtimehelper/translation_butler_page.dart +++ b/lib/home/realtimehelper/translation_butler_page.dart @@ -1,36 +1,22 @@ import 'dart:async'; -import 'package:cached_network_image/cached_network_image.dart'; -import 'package:chat/chat/ChatPage.dart'; import 'package:chat/data/UserData.dart'; -import 'package:chat/data/chat_data_mgr.dart'; -import 'package:chat/data/group_data_mgr.dart'; import 'package:chat/data/translate_hk_data_mgr.dart'; -import 'package:chat/home/add_friend.dart'; -import 'package:chat/home/group_announcement.dart'; -import 'package:chat/home/group_manage_page.dart'; import 'package:chat/models/group_info_model.dart'; import 'package:chat/models/money_change.dart'; -import 'package:chat/models/ref_name_provider.dart'; -import 'package:chat/utils/LoadingDialog.dart'; import 'package:chat/utils/MessageMgr.dart'; -import 'package:chat/utils/group_member_model.dart'; import 'package:chat/utils/msgHandler.dart'; import 'package:chat/utils/screen.dart'; import 'package:chat/utils/sp_utils.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:oktoast/oktoast.dart'; import 'package:provider/provider.dart'; import '../../data/constants.dart'; import '../../generated/i18n.dart'; import '../../r.dart'; import '../../utils/CustomUI.dart'; -import '../../utils/FullWithButton.dart'; -import '../../utils/app_navigator.dart'; -import '../create_group_view.dart'; import 'package:chat/utils/PopUpMenu.dart' as myPop; class TranslationButlerPage extends StatefulWidget { diff --git a/lib/home/realtimehelper/translation_evaluation_dialog.dart b/lib/home/realtimehelper/translation_evaluation_dialog.dart index 865f588..fbfffaf 100644 --- a/lib/home/realtimehelper/translation_evaluation_dialog.dart +++ b/lib/home/realtimehelper/translation_evaluation_dialog.dart @@ -29,13 +29,11 @@ class TravelEvaluationPageState extends State { @override void initState() { - // TODO: implement initState super.initState(); } @override void didChangeDependencies() { - // TODO: implement didChangeDependencies super.didChangeDependencies(); posList = [ EvaluationBean(1, I18n.of(context).translation_pos_1), @@ -56,7 +54,6 @@ class TravelEvaluationPageState extends State { @override Widget build(BuildContext context) { - // TODO: implement build List evaluationWidget = getItem(isGood ? posList : negList); diff --git a/lib/utils/CustomUI.dart b/lib/utils/CustomUI.dart index 40ef4cc..fd2dfed 100644 --- a/lib/utils/CustomUI.dart +++ b/lib/utils/CustomUI.dart @@ -1389,12 +1389,13 @@ class CustomUI { I18n.of(context) .translation_butler_dialog_start_service, () { - - Navigator.of(context).pop(); - },onPress: (){ - MsgHandler.sendReceiveOrder(); - Navigator.of(context).pop(); - },), + Navigator.of(context).pop(); + }, + onPress: () { + MsgHandler.sendReceiveOrder(); + Navigator.of(context).pop(); + }, + ), ) ], ), @@ -1412,4 +1413,15 @@ class CustomUI { child: TravelEvaluationPage(), )); } + + static double getRealTextWidht(String text, double fontSize) { + TextPainter _textPainter = TextPainter( + maxLines: 2, + text: TextSpan( + text: text, + style: TextStyle(fontSize: fontSize, color: Colors.black)), + textDirection: TextDirection.ltr) + ..layout(); + return _textPainter.width; + } } diff --git a/lib/utils/HttpUtil.dart b/lib/utils/HttpUtil.dart index 287e14d..f8bb798 100644 --- a/lib/utils/HttpUtil.dart +++ b/lib/utils/HttpUtil.dart @@ -36,7 +36,6 @@ import 'dart:io'; import '../data/UserData.dart'; import '../utils/TokenMgr.dart'; import 'package:http_parser/http_parser.dart'; -import 'package:chat/utils/friend_list_mgr.dart'; class HttpUtil { static HttpUtil _instance; diff --git a/lib/utils/count_down_button.dart b/lib/utils/count_down_button.dart index ad9690d..33b8c58 100644 --- a/lib/utils/count_down_button.dart +++ b/lib/utils/count_down_button.dart @@ -14,7 +14,7 @@ class CountDownButton extends StatefulWidget{ @override State createState() { - // TODO: implement createState + return CountDownButtonState(); } @@ -44,7 +44,6 @@ class CountDownButtonState extends State { } @override void initState() { - // TODO: implement initState super.initState(); secondsPassed = widget.countDownTime; timer = Timer.periodic(Duration(seconds: 1), (Timer t){ @@ -54,14 +53,12 @@ class CountDownButtonState extends State { @override void dispose() { - // TODO: implement dispose super.dispose(); timer?.cancel(); } @override Widget build(BuildContext context) { - // TODO: implement build // ~/ 取整操作 int seconds = secondsPassed % 60; int minutes = secondsPassed ~/ 60; diff --git a/lib/utils/file_cache_mgr.dart b/lib/utils/file_cache_mgr.dart index cad71a7..7b98866 100644 --- a/lib/utils/file_cache_mgr.dart +++ b/lib/utils/file_cache_mgr.dart @@ -1,5 +1,4 @@ import 'dart:io'; -import 'dart:typed_data'; import 'package:path/path.dart' as p; import 'package:path_provider/path_provider.dart'; diff --git a/lib/utils/image_util.dart b/lib/utils/image_util.dart index df91a60..b9a76c3 100644 --- a/lib/utils/image_util.dart +++ b/lib/utils/image_util.dart @@ -5,7 +5,6 @@ import 'dart:ui'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:chat/data/group_data_mgr.dart'; import 'package:chat/models/group_info_model.dart'; -import 'package:chat/utils/screen.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; diff --git a/lib/utils/msgHandler.dart b/lib/utils/msgHandler.dart index 3d74190..3e6edf2 100644 --- a/lib/utils/msgHandler.dart +++ b/lib/utils/msgHandler.dart @@ -9,7 +9,6 @@ import 'package:chat/data/group_data_mgr.dart'; import 'package:chat/data/translate_hk_data_mgr.dart'; import 'package:chat/generated/i18n.dart'; import 'package:chat/home/IndexPage.dart'; -import 'package:chat/home/realtimehelper/translation_butler_page.dart'; import 'package:chat/models/ChatMsg.dart'; import 'package:chat/models/group_info_model.dart'; import 'package:chat/proto/all.pbserver.dart'; @@ -26,7 +25,6 @@ import 'package:flutter/material.dart'; import 'package:oktoast/oktoast.dart'; import 'package:fixnum/fixnum.dart'; -import 'LoadingDialog.dart'; import 'MessageMgr.dart'; const MaxMsgContentSize = 1024 * 1024 * 3; @@ -414,7 +412,7 @@ class MsgHandler { channelType: ChatChannelType.Group.value); } } - else if(isTranslateHK){ //TODO ddddd + else if(isTranslateHK){ var myId = UserData().basicInfo.userId; TransHKChatNotice notice = TransHKChatNotice.fromBuffer(chat.contentBuff); BaseUserInfo friendId ; diff --git a/lib/utils/screen_shot.dart b/lib/utils/screen_shot.dart index ee13c20..8fa51cf 100644 --- a/lib/utils/screen_shot.dart +++ b/lib/utils/screen_shot.dart @@ -1,7 +1,6 @@ import 'dart:typed_data'; import 'dart:io'; import 'package:chat/map/location_result.dart'; -import 'package:chat/utils/screen.dart'; import 'package:flutter/services.dart'; import 'package:flutter_native_image/flutter_native_image.dart'; //import 'package:flutter_image_compress/flutter_image_compress.dart'; diff --git a/lib/utils/white_opacity_anim.dart b/lib/utils/white_opacity_anim.dart new file mode 100644 index 0000000..be338b1 --- /dev/null +++ b/lib/utils/white_opacity_anim.dart @@ -0,0 +1,52 @@ +import 'package:flutter/material.dart'; + +class WhiteOpacityAnim extends StatefulWidget { + final Widget child; + final animFinishCallback; + WhiteOpacityAnim( + {Key key, @required this.child, @required this.animFinishCallback}); + @override + _WhiteOpacityAnimState createState() => _WhiteOpacityAnimState(); +} + +class _WhiteOpacityAnimState extends State + with SingleTickerProviderStateMixin { + Animation _animation; + AnimationController _controller; + + @override + void initState() { + super.initState(); + // 启动动画controller + _controller = new AnimationController( + duration: Duration(milliseconds: 1000), vsync: this); + _controller.addStatusListener((AnimationStatus status) { + setState(() {}); + if (status == AnimationStatus.completed) { + widget.animFinishCallback(); + } + }); + + _animation = new Tween(begin: 1, end: 0).animate(_controller) + ..addListener(() { + setState(() {}); + }); + + _controller.forward(); + } + + @override + void dispose() { + _controller.stop(); + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + child: widget.child, + color: Colors.white.withOpacity(_animation.value), + ); + } +}