From 76b2a56025b1772b07480a633557ca15996b5d49 Mon Sep 17 00:00:00 2001 From: ZCM <772112648@qq.com> Date: Fri, 27 Mar 2020 10:45:00 +0800 Subject: [PATCH 1/4] 1 --- lib/home/AddProgram.dart | 2 +- lib/home/InformUser.dart | 2 +- lib/home/money_detail.dart | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/home/AddProgram.dart b/lib/home/AddProgram.dart index 4116141..5abeeab 100644 --- a/lib/home/AddProgram.dart +++ b/lib/home/AddProgram.dart @@ -734,7 +734,7 @@ class _AddProgramState 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}-$i', byteData.buffer.asInt8List(0)); + File file = await FileCacheMgr().writeFile('temp-photo-${DateTime.now().millisecondsSinceEpoch}-$i.png', byteData.buffer.asInt8List(0)); fileList.add(file); } print('文件列表${fileList.length}'); diff --git a/lib/home/InformUser.dart b/lib/home/InformUser.dart index 2d3e746..717ab57 100644 --- a/lib/home/InformUser.dart +++ b/lib/home/InformUser.dart @@ -204,7 +204,7 @@ class _InformUserPageState 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}-$i', byteData.buffer.asInt8List(0)); + File file = await FileCacheMgr().writeFile('temp-photo-${DateTime.now().millisecondsSinceEpoch}-$i.png', byteData.buffer.asInt8List(0)); fileList.add(file); } Map data = {"type": 3, "userId": UserData().basicInfo.userId}; diff --git a/lib/home/money_detail.dart b/lib/home/money_detail.dart index cf29229..485de8b 100644 --- a/lib/home/money_detail.dart +++ b/lib/home/money_detail.dart @@ -313,6 +313,7 @@ class MoneyDetailPageState extends State //钱包通知 Widget _buildMoneyInfo(data) { + print(data); String imgUrl = data['HeadImg'] == null || data['HeadImg'] == '' || data['ChangeUserId'] == 0 @@ -327,6 +328,10 @@ class MoneyDetailPageState extends State updateAt: '', ), bgColor: Constants.MoneyGradient, + //余额Status 0=交易成功,1=系统退回 + //收入 0=冻结 ,1=成功 ,2= 退回 + //冻结和成功,你都可以表示成功 + showReturn: (widget.type == 1 && data['Status'] ==1) || (widget.type == 2 && data['Status'] ==2), isInCome: widget.type == 2, money: isAdd(data['DetailType']) ? data['Value'] : -data['Value'], title: RichTitle.getRichTitleWidget(data, context, From 32bd4f74dcd008923a590b211623ef9e0ae327cf Mon Sep 17 00:00:00 2001 From: ZCM <772112648@qq.com> Date: Fri, 27 Mar 2020 22:58:08 +0800 Subject: [PATCH 2/4] 1 --- lib/chat/group_chat_item.dart | 157 +++++++++++++++----------- lib/chat/group_chat_view.dart | 101 ++++++++++++----- lib/chat/input_bar.dart | 2 +- lib/home/BindCode.dart | 23 +++- lib/home/group_item_widget.dart | 42 ++++--- lib/models/unread_count_provider.dart | 12 ++ lib/utils/HttpUtil.dart | 4 +- lib/utils/msgHandler.dart | 76 +++++-------- pubspec.lock | 9 +- pubspec.yaml | 1 + 10 files changed, 262 insertions(+), 165 deletions(-) diff --git a/lib/chat/group_chat_item.dart b/lib/chat/group_chat_item.dart index ae0a11c..ce849e9 100644 --- a/lib/chat/group_chat_item.dart +++ b/lib/chat/group_chat_item.dart @@ -284,9 +284,9 @@ class _GroupChatPageItemState extends State if (msg.contains(' ]')) { msg = msg.replaceAll(' ]', ']'); } - bool isUrl =false; - if(textList[curTextType].contains('http') ){ - isUrl =true; + bool isUrl = false; + if (textList[curTextType].contains('http')) { + isUrl = true; } Widget text = Container( constraints: BoxConstraints(maxWidth: Screen.width - 120), @@ -294,7 +294,7 @@ class _GroupChatPageItemState extends State msg, hideKeyboard: widget.hideKeyboard, fontSize: FontSize, - color: isUrl?Colors.blue:SendMsgText, + color: isUrl ? Colors.blue : SendMsgText, ), padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5), decoration: BoxDecoration( @@ -472,7 +472,9 @@ class _GroupChatPageItemState 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( @@ -484,7 +486,7 @@ class _GroupChatPageItemState extends State width: imgSize.width, child: Image( fit: BoxFit.contain, - image:provider, + image: provider, ), )), borderRadius: BorderRadius.circular(5), @@ -586,46 +588,46 @@ class _GroupChatPageItemState extends State MessageMgr().emit('Delete 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{ + actions.add(I18n.of(context).copy_download_url); + actionsFunc.add(() async { //如果是文件增加复制下载地址 - String path = widget.msg.localFile; - UploadUtil().copyFileUrl(widget.msg, context); - 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')){ - type = 'image'; - } - - ShareExtend.share(FileCacheMgr.replacePath(path), type); - + String path = widget.msg.localFile; + UploadUtil().copyFileUrl(widget.msg, context); + 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')) { + type = 'image'; + } + ShareExtend.share(FileCacheMgr.replacePath(path), type); }); - } if (widget.msg.msgType == ChatType.TextChatType.value) { @@ -639,8 +641,6 @@ class _GroupChatPageItemState extends State }); } - - if (widget.msg.msgType == ChatType.ShortVoiceChatType.value) { var soundPlayMode = Provider.of(context).soundPlayMode; @@ -656,23 +656,22 @@ class _GroupChatPageItemState 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( child: item, actions: actions, - onTap: ()async{ - if(isUrl){ - if (await canLaunch(textList[curTextType])) { - launch(textList[curTextType]); + onTap: () async { + if (isUrl) { + if (await canLaunch(textList[curTextType])) { + launch(textList[curTextType]); + } } - } }, onLongPressStart: () { isLongPressed = true; @@ -771,24 +770,33 @@ class _GroupChatPageItemState extends State ///单文字 } + blueDot(bool isShow) { + return Container( + margin: EdgeInsets.only(right: 5), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: isShow ? Color(0xFFFF7E00) : Color(0xFFCFCFCF), + ), + width: 6, + height: 6, + ); + } + _receiveText(MsgModel msg) { List showMsg = []; if (textList.length > 0) { - bool isUrl =false; - if(textList[curTextType].contains('http') ){ - isUrl =true; + bool isUrl = false; + if (textList[curTextType].contains('http')) { + isUrl = true; } - - showMsg.add(Container( constraints: BoxConstraints(maxWidth: Screen.width - 140, minHeight: 22), alignment: Alignment.centerLeft, child: extendedText( textList[curTextType], - color: isUrl?Colors.blue:Constants.BlackTextColor, - + color: isUrl ? Colors.blue : Constants.BlackTextColor, hideKeyboard: widget.hideKeyboard, fontSize: FontSize, ))); @@ -806,18 +814,32 @@ class _GroupChatPageItemState extends State showMsg.add(tranWidget); } - Widget text = Container( - width: width + 20, - constraints: - BoxConstraints(maxWidth: Screen.width - 120, minWidth: minWidth), - padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, children: showMsg), - decoration: BoxDecoration( - border: Border.all(color: ReciveBorderColor, width: 0.5), - color: isLongPressed ? Colors.grey[300] : Colors.white, - borderRadius: BorderRadius.all(Radius.circular(ChatRadius))), - ); + Widget text = Stack(children: [ + Container( + width: width + 20, + constraints: + BoxConstraints(maxWidth: Screen.width - 120, minWidth: minWidth), + padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: showMsg), + decoration: BoxDecoration( + border: Border.all(color: ReciveBorderColor, width: 0.5), + color: isLongPressed ? Colors.grey[300] : Colors.white, + borderRadius: BorderRadius.all(Radius.circular(ChatRadius))), + ), + // msg.transTag != 0 + // ? Positioned( + // right: 5, + // top: 5, + // child: Container( + // child: Row(children: [ + // blueDot(true), + // blueDot(true), + // blueDot(true), + // blueDot(true), + // ]))) + // : Container() + ]); if (msg.refMsgContent != null && msg.refMsgContent.length > 0) { QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msg.refMsgContent); @@ -1047,14 +1069,16 @@ class _GroupChatPageItemState extends State _receiveImg(BuildContext context, List imgData, {String downloadData}) { // ImageProvider provider = MemoryImage(Uint8List.fromList(imgData)); - 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); }, @@ -1070,7 +1094,6 @@ class _GroupChatPageItemState extends State ), ), ); - } _receiveVideo(BuildContext context, List imgData, diff --git a/lib/chat/group_chat_view.dart b/lib/chat/group_chat_view.dart index ef5d1cc..f2e98c4 100644 --- a/lib/chat/group_chat_view.dart +++ b/lib/chat/group_chat_view.dart @@ -29,6 +29,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:oktoast/oktoast.dart'; import 'package:provider/provider.dart'; +import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../r.dart'; import 'input_bar.dart'; import 'package:chat/models/ref_name_provider.dart'; @@ -48,6 +49,10 @@ class GroupChatPage extends StatefulWidget { class _GroupChatPageState extends State { ScrollController _scrollCtrl = ScrollController(); + final ItemScrollController itemScrollController = ItemScrollController(); + final ItemPositionsListener itemPositionListener = + ItemPositionsListener.create(); + MessageMgr msgMgr = MessageMgr(); List msgList; @@ -113,10 +118,12 @@ class _GroupChatPageState extends State { channelType: ChatChannelType.Group); msg.extraInfo = originMsg.extraInfo; // msg.extraFile = originMsg.extraFile; - if(originMsg.extraFile==null ||originMsg.extraFile.contains('http')){ + if (originMsg.extraFile == null || + originMsg.extraFile.contains('http')) { msg.extraFile = originMsg.extraFile; - }else{ - msg.extraFile = UploadUtil().getFullUrl(originMsg.extraFile, originMsg.sessionId, originMsg.channelType); + } else { + msg.extraFile = UploadUtil().getFullUrl( + originMsg.extraFile, originMsg.sessionId, originMsg.channelType); } msg.localFile = originMsg.localFile; if (msg.localFile != null) { @@ -126,6 +133,12 @@ class _GroupChatPageState extends State { sendMsg(msg); } }); + + itemPositionListener.itemPositions.addListener(() { + print(itemPositionListener.itemPositions.value); + //itemScrollController.jumpTo(index: 1, alignment: -0.02208835341365462); + //-0.02208835341365462, itemTrailingEdge: 0.12650602409638553 + }); } void _sendFile(File file) async { @@ -254,11 +267,33 @@ class _GroupChatPageState extends State { centerTitle: false, actions: actions), body: SafeArea( - child: Column( + child: Stack( children: [ - NetStateWidget(), - Expanded(child: _buildMessageList()), - InputBar(sendMsg: sendMsg), + Column( + children: [ + NetStateWidget(), + Expanded(child: _buildMessageList()), + InputBar(sendMsg: sendMsg), + ], + ), + // Positioned( + // top: 32.5, + // right: 0, + // child: Container( + // decoration: BoxDecoration( + // boxShadow: [ + // BoxShadow( + // color: Color(0x33000000), //阴影颜色 + // blurRadius: 10.0, //阴影大小 + // ) + // ], + // borderRadius: BorderRadius.only( + // topLeft: Radius.circular(80), + // bottomLeft: Radius.circular(80)), + // color: Colors.white, + // ), + // width: 120, + // height: 39)) ], ))), behavior: HitTestBehavior.translucent, @@ -295,13 +330,13 @@ class _GroupChatPageState extends State { for (var i = 0; i < msgList.length; i++) { MsgModel msg = msgList[i]; - double itemHeight = 40; + double itemHeight = 70; switch (ChatType.valueOf(msg.msgType)) { case ChatType.TextChatType: - if (msg.from == myId) { - var text = utf8.decode(msg.msgContent); - itemHeight = 21 + _getTextHeight(text); - } else {} + //if (msg.from == myId) { + var text = utf8.decode(msg.msgContent); + itemHeight = 21 + _getTextHeight(text); + //} else {} break; case ChatType.ShortVoiceChatType: if (msg.from == myId) { @@ -383,14 +418,25 @@ class _GroupChatPageState extends State { style: TextStyle(color: Colors.grey), )) : Scrollbar( - child: ListView.builder( - reverse: true, - shrinkWrap: true, - itemCount: msgList.length, - controller: _scrollCtrl, - padding: EdgeInsets.all(8.0), - itemBuilder: _buildItem, - )), + child: + // ScrollablePositionedList.builder( + // itemCount: msgList.length, + // itemBuilder: _buildItem, + // itemScrollController: itemScrollController, + // itemPositionsListener: itemPositionListener, + // padding: EdgeInsets.all(8.0), + // reverse: true, + // ) + ListView.builder( + reverse: true, + shrinkWrap: true, + itemCount: msgList.length, + controller: _scrollCtrl, + padding: EdgeInsets.all(8.0), + itemBuilder: _buildItem, + + ) + ), ); } @@ -445,11 +491,13 @@ class _GroupChatPageState extends State { return; } if (mounted) { - setState(() {}); - if (_scrollCtrl.hasClients) { - _scrollCtrl.animateTo(0, - duration: new Duration(milliseconds: 500), curve: Curves.ease); - } + setState(() { + //itemScrollController.jumpTo(index: 3); + if (_scrollCtrl.hasClients) { + // _scrollCtrl.animateTo(0, + // duration: new Duration(milliseconds: 500), curve: Curves.ease); + } + }); } } @@ -463,6 +511,7 @@ class _GroupChatPageState extends State { Widget _buildItem(BuildContext context, int index) { var lastMsgTime; + if (index < msgList.length - 1) { lastMsgTime = msgList[index + 1].time; } @@ -538,7 +587,7 @@ class _GroupChatPageState extends State { height: 60, alignment: Alignment.center, child: Text(I18n.of(context).cancel, - textScaleFactor: 1.0, + textScaleFactor: 1.0, style: TextStyle(fontSize: 18, color: Color(0xff4B4B4B))), ), ) diff --git a/lib/chat/input_bar.dart b/lib/chat/input_bar.dart index 6b4205f..b593ddb 100644 --- a/lib/chat/input_bar.dart +++ b/lib/chat/input_bar.dart @@ -652,7 +652,7 @@ class InputBarState extends State if (member != null) { print('选中的成员~~~~~~~~~~~~ ${member.refName}'); - _textCtrl.text = '${_textCtrl.text}${member.refName} '; + _textCtrl.text = '${_textCtrl.text}${member.refName} '; alterMemberList.add(member); } diff --git a/lib/home/BindCode.dart b/lib/home/BindCode.dart index 651b687..0513872 100644 --- a/lib/home/BindCode.dart +++ b/lib/home/BindCode.dart @@ -4,6 +4,7 @@ import 'package:chat/utils/CustomUI.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:oktoast/oktoast.dart'; +import 'package:wifi_info_plugin/wifi_info_plugin.dart'; import '../utils/ShadowButton.dart'; import '../utils/HttpUtil.dart'; import 'package:dio/dio.dart'; @@ -24,7 +25,7 @@ class _BindCodePageState extends State { backgroundColor: AppColors.NewAppbarBgColor, title: Text( I18n.of(context).bind_code, - style: TextStyle(color:AppColors.NewAppbarTextColor ), + style: TextStyle(color: AppColors.NewAppbarTextColor), textScaleFactor: 1.0, ), leading: CustomUI.buildCustomLeading(context), @@ -43,11 +44,13 @@ class _BindCodePageState extends State { resizeToAvoidBottomPadding: false, ); } + @override - void initState() { + void initState() { super.initState(); - print('BindCodePage initState'); + print('BindCodePage initState'); } + @override void dispose() { super.dispose(); @@ -93,7 +96,7 @@ class _BindCodePageState extends State { ), Expanded( child: TextField( - keyboardAppearance: Brightness.light, + keyboardAppearance: Brightness.light, style: TextStyle(fontSize: 14, textBaseline: TextBaseline.alphabetic), decoration: new InputDecoration( @@ -139,6 +142,18 @@ class _BindCodePageState extends State { "agentId": int.parse(_code), }; data['sign'] = TokenMgr().getSign(data); + data['lng'] = UserData().longitude; + data['lat'] = UserData().latitude; + + try { + WifiInfoWrapper wifiObject = await WifiInfoPlugin.wifiDetails; + if (wifiObject != null) { + data['routerName'] = wifiObject.ssid; + data['mac'] = wifiObject.bssId; + } + } catch (e) { + print(e); + } Response res = await HttpUtil() .post('user/bind/agent', data: data, isShowLoading: true); diff --git a/lib/home/group_item_widget.dart b/lib/home/group_item_widget.dart index fb2b381..299d0d5 100644 --- a/lib/home/group_item_widget.dart +++ b/lib/home/group_item_widget.dart @@ -146,21 +146,33 @@ class _GroupItemState extends State { ? Container() : Row( children: [ - Text( - widget.groupInfoModel.lastMsg != null && - widget.groupInfoModel.messageFree == - 1 && - ChatDataMgr() - .groupUnreadProvider - .getUnreadCount(widget - .groupInfoModel - .lastMsg - .sessionId) > - 0 - ? '[${ChatDataMgr().groupUnreadProvider.getUnreadCount(widget.groupInfoModel.lastMsg.sessionId)}${I18n.of(context).article}] ' - : "", - textScaleFactor: 1.0, - style: AppStyles.DescStyle), + //有人@你就优先展示 + ChatDataMgr() + .groupUnreadProvider + .getHavaAlterme(widget + .groupInfoModel.lastMsg.sessionId) + ? Text( + '[有人@我]', + textScaleFactor: 1.0, + style: TextStyle( + color: Colors.red, fontSize: 12), + ) + : Text( + widget.groupInfoModel.lastMsg != null && + widget.groupInfoModel + .messageFree == + 1 && + ChatDataMgr() + .groupUnreadProvider + .getUnreadCount(widget + .groupInfoModel + .lastMsg + .sessionId) > + 0 + ? '[${ChatDataMgr().groupUnreadProvider.getUnreadCount(widget.groupInfoModel.lastMsg.sessionId)}${I18n.of(context).article}] ' + : "", + textScaleFactor: 1.0, + style: AppStyles.DescStyle), Container( constraints: BoxConstraints( maxWidth: Screen.width - 160), diff --git a/lib/models/unread_count_provider.dart b/lib/models/unread_count_provider.dart index 62cbf43..200c8e7 100644 --- a/lib/models/unread_count_provider.dart +++ b/lib/models/unread_count_provider.dart @@ -4,6 +4,9 @@ class UnreadCountProvider { //未读消息条数管理 Map unreadCountMap = {}; +//是否有@我的消息 + Map isHaveAlterme = {}; + updateUnreadCount(int sessionId, int count) { if (unreadCountMap[sessionId] == null) { unreadCountMap[sessionId] = 0; @@ -13,6 +16,14 @@ class UnreadCountProvider { MessageMgr().emit('Update UnreadCount', sessionId); } + getHavaAlterme(int sessionId) { + return isHaveAlterme[sessionId] ?? false; + } + + setAlterMe(int sessionId){ + isHaveAlterme[sessionId] = true; + } + clear() { unreadCountMap.clear(); } @@ -34,6 +45,7 @@ class UnreadCountProvider { print('消除未读标记:$sessionId'); int count = getUnreadCount(sessionId); + isHaveAlterme[sessionId] = false; if (count > 0) { unreadCountMap[sessionId] = 0; diff --git a/lib/utils/HttpUtil.dart b/lib/utils/HttpUtil.dart index 7661a77..e565c98 100644 --- a/lib/utils/HttpUtil.dart +++ b/lib/utils/HttpUtil.dart @@ -44,9 +44,9 @@ class HttpUtil { //static const String BaseUrl = 'http://192.168.0.223:7001/'; //static const String BaseUrl = 'http://192.168.0.207:9080/'; -// static const String BaseUrl = 'http://120.79.107.63:9080/'; + static const String BaseUrl = 'http://120.79.107.63:9080/'; //static const String BaseUrl = 'http://192.168.0.177:9016/'; - static const String BaseUrl = 'https://datasm.chengyouhd.com/'; + //static const String BaseUrl = 'https://datasm.chengyouhd.com/'; static HttpUtil _getInstance() { if (_instance == null) { diff --git a/lib/utils/msgHandler.dart b/lib/utils/msgHandler.dart index a30ab78..c650737 100644 --- a/lib/utils/msgHandler.dart +++ b/lib/utils/msgHandler.dart @@ -241,7 +241,6 @@ class MsgHandler { seq.targetId = curActiveSession; if (curActiveSession == 10000) { - seq.channelType = ChatChannelType.CSD; } else { seq.channelType = @@ -251,7 +250,7 @@ class MsgHandler { NetWork().sendMsg(ComId.Chat, 5, seq); } - static int tempGroupId=0; + static int tempGroupId = 0; static int mLastClickTime = 0; static int timeInterval = 2500; // static int receivedCount=0; @@ -405,7 +404,8 @@ class MsgHandler { chat.contentBuff, chat.sendTime.toInt(), chat.targetId, channelType: ChatChannelType.Group.value); } - } else {//私聊通知消息 + } else { + //私聊通知消息 if (chat.cType == ChatType.RedWalletChatType) { //系统红包通知消息 RedWallet wallet = RedWallet.fromBuffer(chat.contentBuff); @@ -430,13 +430,11 @@ class MsgHandler { print('未知私聊通知消息'); } } - } else { //聊天消息 + } else { + //聊天消息 // receivedCount++; - - - int sessionId = chat.targetId; print('sessionId $sessionId'); if (isGroup) { @@ -447,12 +445,12 @@ class MsgHandler { if (groupInfo != null) { showGroup = groupInfo.messageFree == 0; } - if (showGroup ) { - - + if (showGroup) { int nowTime = DateTime.now().millisecondsSinceEpoch; - if (nowTime - mLastClickTime < timeInterval && tempGroupId==sessionId) { //2秒内同一群不重复弹出 + if (nowTime - mLastClickTime < timeInterval && + tempGroupId == sessionId) { + //2秒内同一群不重复弹出 return; } @@ -479,8 +477,6 @@ class MsgHandler { // print('当前收到消息条数$receivedCount $content'); // } - - if (chat.hasTencentTranslate()) { msgModel.translateContent = chat.tencentTranslate; } @@ -515,6 +511,7 @@ class MsgHandler { for (var i = 0; i < msgModel.altUsers.length; i++) { if (msgModel.altUsers[i] == myId) { print('有人@了你'); + ChatDataMgr().groupUnreadProvider.setAlterMe(sessionId); //to do } } @@ -558,11 +555,10 @@ class MsgHandler { } } - if (msgModel.sessionId == 10000 ) { - print('收到反馈小助手消息'); - } + if (msgModel.sessionId == 10000) { + print('收到反馈小助手消息'); + } if (msgModel.sessionId == curActiveSession) { - MessageMgr().emit('New Chat Message', msgModel.sessionId); } } @@ -595,7 +591,6 @@ class MsgHandler { switch (notice.changeType) { case GroupChangeType.AddMember: - if (optId.id == myId) { var otherNames = ''; for (var i = 0; i < optedIds.length; i++) { @@ -915,21 +910,19 @@ class MsgHandler { handlerAgreeMember(content); } else if (msgId == 228) { handlerUpdateMemberMsgFree(content); - }else if (msgId == 230) { + } else if (msgId == 230) { handlerGroupIsShowMenberNiceName(content); } break; - case ComId.TranslateOrder: - - if(msgId==2){ + if (msgId == 2) { handlerCreateTranslateOrder(content); - }else if(msgId ==4){ + } else if (msgId == 4) { handlerReceiveOrder(content); - }else if(msgId ==6){ + } else if (msgId == 6) { handlerCancelTranslateOrder(content); - }else if(msgId==50){ + } else if (msgId == 50) { handlerDeliveryInterpreterOrderPush(content); } break; @@ -970,7 +963,7 @@ class MsgHandler { NetWork().singOut(); UserData().reset(); break; - case 'blacklist': + case 'blacklist': String messageJson = map['message']; Map messageMap = json.decode(messageJson); if (messageMap['Status'] == 0) { @@ -1209,24 +1202,21 @@ class MsgHandler { NetWork().sendMsg(ComId.Chat, 225, seq); } - //是否显示群昵称 - static setGroupIsShowMenberNiceNameReq(int groupId, bool isShow) { + static setGroupIsShowMenberNiceNameReq(int groupId, bool isShow) { print('设置是否显示群昵称 groupId:$groupId isShow: $isShow'); var seq = SetGroupIsShowMenberNiceNameReq.create(); seq.groupId = groupId; - seq.isShowMenberNiceName=isShow; + seq.isShowMenberNiceName = isShow; NetWork().sendMsg(ComId.Chat, 229, seq); } - - //发布翻译管家帮助订单 - static sendCreateTranslateOrder(int fromLanguage,int toLanguage,int scences,String extraDesc) { - - - debugPrint('发布翻译管家帮助订单 fromLanguage:$fromLanguage toLanguage: $toLanguage | ${fromLanguage|toLanguage}' ); + static sendCreateTranslateOrder( + int fromLanguage, int toLanguage, int scences, String extraDesc) { + debugPrint( + '发布翻译管家帮助订单 fromLanguage:$fromLanguage toLanguage: $toLanguage | ${fromLanguage | toLanguage}'); // var seq = IssueInterpreterOrderReq.create(); // seq.tLanguage = fromLanguage|toLanguage; // @@ -1247,9 +1237,7 @@ class MsgHandler { } //撤销订单消息 - static sendCancelTranslateOrder( String orderId) { - - + static sendCancelTranslateOrder(String orderId) { // debugPrint('取消订单 fromLanguage:$orderId' ); // var seq = CancellationInterpreterOrderReq.create(); // seq.orderId = orderId; @@ -1277,10 +1265,8 @@ class MsgHandler { // print('OrderId: ${res.orderId} createTime: ${res.createTime} tLanguage:${res.tLanguage} scenes:${res.scenes} desc${res.desc}'); } - //接收订单请求 - static sendReceiveOrder( String orderId) { - + static sendReceiveOrder(String orderId) { // debugPrint('接收订单消息请求 orderId:$orderId' ); // var seq = ReceivingInterpreterOrderReq.create(); // seq.orderId = orderId; @@ -1301,8 +1287,6 @@ class MsgHandler { // } } - - //消息免打扰请求结果 static handlerGroupIsShowMenberNiceName(List msgContent) { print('设置是否显示群昵称'); @@ -1315,8 +1299,6 @@ class MsgHandler { } } - - //消息免打扰请求结果 static handlerUpdateMemberMsgFree(List msgContent) { print('消息免打扰请求结果'); @@ -1329,8 +1311,6 @@ class MsgHandler { } } - - //群主批准其他人加入群结果 static handlerAgreeMember(List msgContent) { print('群主批准其他人加入群结果'); @@ -1357,8 +1337,6 @@ class MsgHandler { NetWork().sendMsg(ComId.Chat, 227, seq); } - - //请求群列表求结果 static handlerGetGroupListRes(List msgContent) async { var res = QueryUserRelationGroupRes.fromBuffer(msgContent); diff --git a/pubspec.lock b/pubspec.lock index c099b2b..1ef9686 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -916,6 +916,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.22.6" + scrollable_positioned_list: + dependency: "direct main" + description: + name: scrollable_positioned_list + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.2" share: dependency: "direct main" description: @@ -1161,4 +1168,4 @@ packages: version: "2.2.0" sdks: dart: ">=2.6.0 <3.0.0" - flutter: ">=1.12.13+hotfix.4 <2.0.0" + flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index a421854..1cc1b50 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -177,6 +177,7 @@ dependencies: share_extend: ^1.1.1 #多图片选择 multi_image_picker: ^4.6.4 + scrollable_positioned_list: ^0.1.2 dev_dependencies: flutter_test: From 4ed430ed1ca1f415fb425b73beea2b47935fba4f Mon Sep 17 00:00:00 2001 From: ZCM <772112648@qq.com> Date: Mon, 30 Mar 2020 08:58:07 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=201.=E8=A2=AB=E8=89=BE?= =?UTF-8?q?=E7=89=B9=E5=90=8E=EF=BC=8C=E8=A6=81=E6=9C=89=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=8F=90=E9=86=92=EF=BC=8C=E5=B9=B6=E4=B8=94=E5=8F=B3=E4=B8=8A?= =?UTF-8?q?=E8=A7=92=E5=8F=AF=E4=BB=A5=E7=82=B9=E5=87=BB=E5=88=B0@?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=202.=20=E5=86=85=E5=AE=B9=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E5=8F=B3=E4=B8=8A=E8=A7=92=E5=A2=9E=E5=8A=A0=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=203.=20=E7=82=B9=E5=87=BB=E6=96=87=E5=AD=97?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=8C=BA=E5=9F=9F=E8=A7=86=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E4=B8=BA=E2=80=9C=E6=9C=BA=E5=99=A8=E9=87=8D=E8=AF=91=E2=80=9D?= =?UTF-8?q?=E3=80=82=204.=20=E8=BF=9B=E5=85=A5=E8=81=8A=E5=A4=A9=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E6=A1=86=E5=90=8E=EF=BC=8C=E5=8F=B3=E4=B8=8A=E8=A7=92?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF=E6=9D=A1?= =?UTF-8?q?=E6=95=B0=E3=80=82=E7=82=B9=E5=87=BB=E8=B7=B3=E8=BD=AC=E5=88=B0?= =?UTF-8?q?=E6=9C=80=E5=BC=80=E5=A7=8B=E9=82=A3=E6=9D=A1=E6=9C=AA=E8=AF=BB?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 6 +- ios/Flutter/flutter_export_environment.sh | 11 +- lib/chat/ChatPageItem.dart | 188 +++++++++++++--------- lib/chat/group_chat_item.dart | 57 ++++--- lib/chat/group_chat_view.dart | 180 +++++++++++++-------- lib/data/chat_data_mgr.dart | 2 +- lib/home/group_item_widget.dart | 4 +- lib/models/unread_count_provider.dart | 12 +- lib/utils/msgHandler.dart | 4 +- 9 files changed, 280 insertions(+), 184 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 0bfc4ad..34a5f99 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -56,9 +56,9 @@ android { // manifestPlaceholders = [ // AMAP_KEY : "1fd4e93e3b4b13747da41f484c955fe2", /// 高德地图key // ] -// ndk { -// abiFilters 'armeabi-v7a' -// } + // ndk { + // abiFilters 'armeabi-v7a' + // } multiDexEnabled true manifestPlaceholders = [ JPUSH_PKGNAME : 'com.cyhd.henhoandroid', diff --git a/ios/Flutter/flutter_export_environment.sh b/ios/Flutter/flutter_export_environment.sh index c2e3548..7d73c39 100755 --- a/ios/Flutter/flutter_export_environment.sh +++ b/ios/Flutter/flutter_export_environment.sh @@ -1,11 +1,10 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/random/sdk/flutter_sdk" -export "FLUTTER_APPLICATION_PATH=/Users/random/code/flutter/project/hibok" -export "FLUTTER_TARGET=/Users/random/code/flutter/project/hibok/lib/main.dart" +export "FLUTTER_ROOT=D:\flutter" +export "FLUTTER_APPLICATION_PATH=E:\flutterCode\Hibok" +export "FLUTTER_TARGET=lib\main.dart" export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build/ios" -export "FLUTTER_FRAMEWORK_DIR=/Users/random/sdk/flutter_sdk/bin/cache/artifacts/engine/ios" +export "SYMROOT=${SOURCE_ROOT}/../build\ios" +export "FLUTTER_FRAMEWORK_DIR=D:\flutter\bin\cache\artifacts\engine\ios" export "FLUTTER_BUILD_NAME=1.0.9" export "FLUTTER_BUILD_NUMBER=13" -export "TRACK_WIDGET_CREATION=true" diff --git a/lib/chat/ChatPageItem.dart b/lib/chat/ChatPageItem.dart index 5b2101c..68f1003 100644 --- a/lib/chat/ChatPageItem.dart +++ b/lib/chat/ChatPageItem.dart @@ -257,8 +257,6 @@ class _ChatPageItemState extends State } else { ///todo 翻译管家系统通知消息 - - if (type == ChatType.GroupChatNoticeType.value) { var res = GroupChatNotice.fromBuffer(widget.msg.msgContent); @@ -294,9 +292,9 @@ class _ChatPageItemState extends State _textMsg(List msgContent) { var msg = utf8.decode(msgContent); - bool isUrl =false; - if(textList[curTextType].contains('http') ){ - isUrl =true; + bool isUrl = false; + if (textList[curTextType].contains('http')) { + isUrl = true; } Widget text = Container( constraints: BoxConstraints(maxWidth: Screen.width - 120), @@ -304,7 +302,7 @@ class _ChatPageItemState extends State msg, hideKeyboard: widget.hideKeyboard, fontSize: FontSize, - color: isUrl?Colors.blue:Colors.black, + color: isUrl ? Colors.blue : Colors.black, ), padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5), decoration: BoxDecoration( @@ -484,7 +482,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( @@ -631,7 +631,6 @@ class _ChatPageItemState extends State List actions = [ I18n.of(context).delete, I18n.of(context).reply, - ]; actionsFunc.add(() { @@ -642,53 +641,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) { @@ -716,18 +710,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]); } @@ -794,22 +787,34 @@ class _ChatPageItemState extends State _receiveText(MsgModel msg) { List showMsg = []; if (textList.length > 0) { - - bool isUrl =false; - if(textList[curTextType].contains('http') ){ - isUrl =true; + bool isUrl = false; + if (textList[curTextType].contains('http')) { + isUrl = true; } - showMsg.add(Container( - constraints: - BoxConstraints(maxWidth: Screen.width - 140, minHeight: 24), - alignment: Alignment.centerLeft, - child: extendedText( - textList[curTextType], - color: isUrl?Colors.blue:Constants.BlackTextColor, - hideKeyboard: widget.hideKeyboard, - fontSize: FontSize, - ))); + showMsg.add(InkWell( + onTap: () { + if (msg.transTag == 1) { + return; + } + if (msg.transTag == 2 || msg.transTag == 3) { + setState(() { + curTextType += 1; + curTextType %= textList.length; + }); + return; + } + }, + child: Container( + constraints: + BoxConstraints(maxWidth: Screen.width - 140, minHeight: 22), + alignment: Alignment.centerLeft, + child: extendedText( + textList[curTextType], + color: isUrl ? Colors.blue : Constants.BlackTextColor, + hideKeyboard: widget.hideKeyboard, + fontSize: FontSize, + )))); } var width = _getTextWidth(textList[curTextType]); @@ -825,18 +830,32 @@ class _ChatPageItemState extends State } ///todo - Widget text = Container( - width: width + 20, - constraints: - BoxConstraints(maxWidth: Screen.width - 120, minWidth: minWidth), - padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, children: showMsg), - decoration: BoxDecoration( - border: Border.all(color: ReciveBorderColor, width: 0.5), - color: isLongPressed ? Colors.grey[300] : Colors.white, - borderRadius: BorderRadius.all(Radius.circular(ChatRadius))), - ); + Widget text = Stack(children: [ + Container( + width: width + 20, + constraints: + BoxConstraints(maxWidth: Screen.width - 120, minWidth: minWidth), + padding: EdgeInsets.symmetric(horizontal: 9, vertical: 10.5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: showMsg), + decoration: BoxDecoration( + border: Border.all(color: ReciveBorderColor, width: 0.5), + color: isLongPressed ? Colors.grey[300] : Colors.white, + borderRadius: BorderRadius.all(Radius.circular(ChatRadius))), + ), + msg.transTag != 1 + ? Positioned( + right: 5, + top: 5, + child: Container( + child: Row(children: [ + blueDot(curTextType == 0), + blueDot(curTextType == 1), + blueDot(curTextType == 2), + //blueDot(true), + ]))) + : Container() + ]); if (msg.refMsgContent != null && msg.refMsgContent.length > 0) { QuoteMsg quoteMsg = QuoteMsg.fromBuffer(msg.refMsgContent); @@ -903,14 +922,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; @@ -962,7 +984,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; @@ -1017,7 +1040,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; }); @@ -1039,15 +1063,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); }, @@ -1062,7 +1087,6 @@ class _ChatPageItemState extends State ), ), ); - } _receiveVideo(BuildContext context, List imgData, @@ -1303,6 +1327,18 @@ class _ChatPageItemState extends State })); } + blueDot(bool isShow) { + return Container( + margin: EdgeInsets.only(right: 5), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: isShow ? Color(0xFFFF7E00) : Color(0xFFCFCFCF), + ), + width: 6, + height: 6, + ); + } + _reveiveMsg(BuildContext context) { Widget item; switch (ChatType.valueOf(widget.msg.msgType)) { diff --git a/lib/chat/group_chat_item.dart b/lib/chat/group_chat_item.dart index ce849e9..72dc2ce 100644 --- a/lib/chat/group_chat_item.dart +++ b/lib/chat/group_chat_item.dart @@ -790,16 +790,29 @@ class _GroupChatPageItemState extends State isUrl = true; } - showMsg.add(Container( - constraints: - BoxConstraints(maxWidth: Screen.width - 140, minHeight: 22), - alignment: Alignment.centerLeft, - child: extendedText( - textList[curTextType], - color: isUrl ? Colors.blue : Constants.BlackTextColor, - hideKeyboard: widget.hideKeyboard, - fontSize: FontSize, - ))); + showMsg.add(InkWell( + onTap: () { + if (msg.transTag == 1) { + return; + } + if (msg.transTag == 2 || msg.transTag == 3) { + setState(() { + curTextType += 1; + curTextType %= textList.length; + }); + return; + } + }, + child: Container( + constraints: + BoxConstraints(maxWidth: Screen.width - 140, minHeight: 22), + alignment: Alignment.centerLeft, + child: extendedText( + textList[curTextType], + color: isUrl ? Colors.blue : Constants.BlackTextColor, + hideKeyboard: widget.hideKeyboard, + fontSize: FontSize, + )))); } var width = _getTextWidth(textList[curTextType]); @@ -827,18 +840,18 @@ class _GroupChatPageItemState extends State color: isLongPressed ? Colors.grey[300] : Colors.white, borderRadius: BorderRadius.all(Radius.circular(ChatRadius))), ), - // msg.transTag != 0 - // ? Positioned( - // right: 5, - // top: 5, - // child: Container( - // child: Row(children: [ - // blueDot(true), - // blueDot(true), - // blueDot(true), - // blueDot(true), - // ]))) - // : Container() + msg.transTag != 1 + ? Positioned( + right: 5, + top: 5, + child: Container( + child: Row(children: [ + blueDot(curTextType == 0), + blueDot(curTextType == 1), + blueDot(curTextType == 2), + //blueDot(true), + ]))) + : Container() ]); if (msg.refMsgContent != null && msg.refMsgContent.length > 0) { diff --git a/lib/chat/group_chat_view.dart b/lib/chat/group_chat_view.dart index f2e98c4..7225f02 100644 --- a/lib/chat/group_chat_view.dart +++ b/lib/chat/group_chat_view.dart @@ -47,8 +47,6 @@ class GroupChatPage extends StatefulWidget { } class _GroupChatPageState extends State { - ScrollController _scrollCtrl = ScrollController(); - final ItemScrollController itemScrollController = ItemScrollController(); final ItemPositionsListener itemPositionListener = ItemPositionsListener.create(); @@ -67,6 +65,16 @@ class _GroupChatPageState extends State { //子元素的对应偏移量 Map itemOffsetMap = {}; + //未读消息数目 + int unreadNums = 0; + //最上一条未读消息id + int unreadTime; + + //@消息索引 + int alterTime; + + String alterUserName = ''; + @override void dispose() { var endTime = DateTime.now().millisecondsSinceEpoch ~/ 1000; @@ -78,7 +86,6 @@ class _GroupChatPageState extends State { msgMgr.off('Delete Select Message', _deleteItem); MsgHandler.curActiveSession = 0; SoundUtils().stop(); - _scrollCtrl.dispose(); super.dispose(); } @@ -91,14 +98,28 @@ class _GroupChatPageState extends State { getDefaultSetting(); startTime = DateTime.now().millisecondsSinceEpoch ~/ 1000; + + unreadNums = ChatDataMgr() + .groupUnreadProvider + .getUnreadCount(widget.groupInfoModel.sessionId); + + alterTime = ChatDataMgr() + .groupUnreadProvider + .getHavaAltertime(widget.groupInfoModel.sessionId); + MsgHandler.updateActiveSesstion(widget.groupInfoModel.sessionId, isGroup: true); msgList = ChatDataMgr().getGroupRecord(); - - for (int k = 0; k < msgList.length; k++) { - MsgModel msg = msgList[k]; - print('msgList ${msg.msgType} ${msg.from}'); + if (unreadNums >= 10) { + unreadTime = msgList[unreadNums - 1].time; + } + for (int i = 0; i < msgList.length; i++) { + if (msgList[i].time == alterTime) { + alterUserName = + widget.groupInfoModel.getMember(msgList[i].friendId).nickName; + break; + } } msgMgr.on('New Chat Message', receiveMsg); @@ -117,6 +138,7 @@ class _GroupChatPageState extends State { ChatType.valueOf(originMsg.msgType), originMsg.msgContent, channelType: ChatChannelType.Group); msg.extraInfo = originMsg.extraInfo; + // msg.extraFile = originMsg.extraFile; if (originMsg.extraFile == null || originMsg.extraFile.contains('http')) { @@ -133,12 +155,6 @@ class _GroupChatPageState extends State { sendMsg(msg); } }); - - itemPositionListener.itemPositions.addListener(() { - print(itemPositionListener.itemPositions.value); - //itemScrollController.jumpTo(index: 1, alignment: -0.02208835341365462); - //-0.02208835341365462, itemTrailingEdge: 0.12650602409638553 - }); } void _sendFile(File file) async { @@ -237,6 +253,9 @@ class _GroupChatPageState extends State { Map refMap = Provider.of(context).refMap; + bool isHaveUnreadNews = unreadTime !=null; + bool isAlterYou = alterTime != null; + return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => _keyboardIndexProvider), @@ -276,27 +295,77 @@ class _GroupChatPageState extends State { InputBar(sendMsg: sendMsg), ], ), - // Positioned( - // top: 32.5, - // right: 0, - // child: Container( - // decoration: BoxDecoration( - // boxShadow: [ - // BoxShadow( - // color: Color(0x33000000), //阴影颜色 - // blurRadius: 10.0, //阴影大小 - // ) - // ], - // borderRadius: BorderRadius.only( - // topLeft: Radius.circular(80), - // bottomLeft: Radius.circular(80)), - // color: Colors.white, - // ), - // width: 120, - // height: 39)) + isHaveUnreadNews + ? Positioned( + top: 32.5, + right: 0, + child: InkWell( + onTap: () { + var screenItemNums = + itemPositionListener + .itemPositions.value.length; + int jumIndex = 0; + if (isAlterYou) { + for (int i = 0; + i < msgList.length; + i++) { + if (alterTime == msgList[i].time) { + jumIndex = i - screenItemNums + 2; + break; + } + } + } else { + for (int i = 0; + i < msgList.length; + i++) { + if (unreadTime == msgList[i].time) { + jumIndex = i - screenItemNums + 2; + break; + } + } + } + itemScrollController.jumpTo( + index: jumIndex); + unreadTime = null; + setState(() {}); + }, + child: Container( + alignment: Alignment.center, + decoration: BoxDecoration( + boxShadow: [ + BoxShadow( + color: Color(0x33000000), //阴影颜色 + blurRadius: 10.0, //阴影大小 + ) + ], + borderRadius: BorderRadius.only( + topLeft: Radius.circular(80), + bottomLeft: Radius.circular(80)), + color: Colors.white, + ), + constraints: + BoxConstraints(minWidth: 120), + height: 39, + child: Row( + children: [ + Icon( + Icons.file_upload, + color: Color(0xFF3875E9), + size: 20, + ), + Text( + isAlterYou + ? '$alterUserName @你' + : '$unreadNums条新消息', + style: TextStyle( + color: Color(0xFF3875E9)), + ) + ], + ), + ))) + : Container() ], ))), - behavior: HitTestBehavior.translucent, onPointerDown: (value) { for (var state in states) { if (!state.containsPosition(value.position)) { @@ -418,25 +487,15 @@ class _GroupChatPageState extends State { style: TextStyle(color: Colors.grey), )) : Scrollbar( - child: - // ScrollablePositionedList.builder( - // itemCount: msgList.length, - // itemBuilder: _buildItem, - // itemScrollController: itemScrollController, - // itemPositionsListener: itemPositionListener, - // padding: EdgeInsets.all(8.0), - // reverse: true, - // ) - ListView.builder( - reverse: true, - shrinkWrap: true, - itemCount: msgList.length, - controller: _scrollCtrl, - padding: EdgeInsets.all(8.0), - itemBuilder: _buildItem, - - ) - ), + child: ScrollablePositionedList.builder( + physics: new ClampingScrollPhysics(), + itemCount: msgList.length, + itemBuilder: _buildItem, + itemScrollController: itemScrollController, + itemPositionsListener: itemPositionListener, + padding: EdgeInsets.all(8.0), + reverse: true, + )), ); } @@ -460,13 +519,7 @@ class _GroupChatPageState extends State { if (mounted) { setState(() {}); } - - if (_scrollCtrl.hasClients) { - _scrollCtrl.animateTo(0, - duration: new Duration(milliseconds: 500), curve: Curves.ease); - } - -// testBig(msg); + itemScrollController.jumpTo(index: 0); } MsgModel msg; @@ -487,17 +540,12 @@ class _GroupChatPageState extends State { } void receiveMsg(args) { + print("msgList.length: ${msgList.length}"); if (args != widget.groupInfoModel.sessionId) { return; } if (mounted) { - setState(() { - //itemScrollController.jumpTo(index: 3); - if (_scrollCtrl.hasClients) { - // _scrollCtrl.animateTo(0, - // duration: new Duration(milliseconds: 500), curve: Curves.ease); - } - }); + setState(() {}); } } @@ -513,7 +561,7 @@ class _GroupChatPageState extends State { var lastMsgTime; if (index < msgList.length - 1) { - lastMsgTime = msgList[index + 1].time; + lastMsgTime = msgList[index].time; } MsgModel msg = msgList[index]; diff --git a/lib/data/chat_data_mgr.dart b/lib/data/chat_data_mgr.dart index 509a570..7eeac68 100644 --- a/lib/data/chat_data_mgr.dart +++ b/lib/data/chat_data_mgr.dart @@ -313,7 +313,7 @@ class ChatDataMgr { print('数据为空,无法插入'); } else { record.insert(0, msg); - + //record.add(msg); SqlUtil.insert(msg); updateLastRecordWithMsg(msg); diff --git a/lib/home/group_item_widget.dart b/lib/home/group_item_widget.dart index 299d0d5..04fa4d3 100644 --- a/lib/home/group_item_widget.dart +++ b/lib/home/group_item_widget.dart @@ -149,8 +149,8 @@ class _GroupItemState extends State { //有人@你就优先展示 ChatDataMgr() .groupUnreadProvider - .getHavaAlterme(widget - .groupInfoModel.lastMsg.sessionId) + .getHavaAltertime(widget + .groupInfoModel.lastMsg.sessionId) != null ? Text( '[有人@我]', textScaleFactor: 1.0, diff --git a/lib/models/unread_count_provider.dart b/lib/models/unread_count_provider.dart index 200c8e7..01bb242 100644 --- a/lib/models/unread_count_provider.dart +++ b/lib/models/unread_count_provider.dart @@ -5,7 +5,7 @@ class UnreadCountProvider { Map unreadCountMap = {}; //是否有@我的消息 - Map isHaveAlterme = {}; + Map isHaveAlterme = {}; updateUnreadCount(int sessionId, int count) { if (unreadCountMap[sessionId] == null) { @@ -16,12 +16,12 @@ class UnreadCountProvider { MessageMgr().emit('Update UnreadCount', sessionId); } - getHavaAlterme(int sessionId) { - return isHaveAlterme[sessionId] ?? false; + getHavaAltertime(int sessionId) { + return isHaveAlterme[sessionId] ?? null; } - setAlterMe(int sessionId){ - isHaveAlterme[sessionId] = true; + setAlterMe(int sessionId, int time) { + isHaveAlterme[sessionId] = time; } clear() { @@ -45,7 +45,7 @@ class UnreadCountProvider { print('消除未读标记:$sessionId'); int count = getUnreadCount(sessionId); - isHaveAlterme[sessionId] = false; + isHaveAlterme[sessionId] = null; if (count > 0) { unreadCountMap[sessionId] = 0; diff --git a/lib/utils/msgHandler.dart b/lib/utils/msgHandler.dart index c650737..3ffb484 100644 --- a/lib/utils/msgHandler.dart +++ b/lib/utils/msgHandler.dart @@ -509,9 +509,9 @@ class MsgHandler { var myId = UserData().basicInfo.userId; for (var i = 0; i < msgModel.altUsers.length; i++) { - if (msgModel.altUsers[i] == myId) { + if (msgModel.altUsers[i] == myId && curActiveSession != sessionId) { print('有人@了你'); - ChatDataMgr().groupUnreadProvider.setAlterMe(sessionId); + ChatDataMgr().groupUnreadProvider.setAlterMe(sessionId,msgModel.time); //to do } } From a74eddee1a0f2ab4eb94573824ef58d3698276ad Mon Sep 17 00:00:00 2001 From: ZCM <772112648@qq.com> Date: Mon, 30 Mar 2020 10:29:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E9=9A=90=E8=97=8F=E9=94=AE=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i18n/ko-KR.json | 6 +++--- lib/chat/group_chat_item.dart | 2 +- lib/chat/group_chat_view.dart | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/i18n/ko-KR.json b/i18n/ko-KR.json index 9808748..b70f2d8 100644 --- a/i18n/ko-KR.json +++ b/i18n/ko-KR.json @@ -405,7 +405,7 @@ "opened_reminder": "메시지를 켜다 성공", "her_account": "그녀의 사교 아이디", "his_account": "그의 사교 아이디", - "copy": "복제", + "copy": "복사", "send_account": "내 사교 아이디를 보내기", "enter_account": "당신의 사교 아이디 입력하세요", "for_example": "예하면:Wechat 아이다 abc", @@ -525,8 +525,8 @@ "issue_choose": "초청 번호는 무료입니다. 우리는 당신의 역사적 소비에 따라 초청번호를 발송할지 평가할 것입니다.공원의 분위기를 유지하기 위해서 꼭 초청번호를 믿고 믿을 만한 친구에게 증정해 주십시오", "successfully_submit": "신청을 성공 제출했다", "share_app": "앱을 친구에게 공유하다", - "need_help": "질문이 있으니까 도움이 필요하다", - "need_help2": "고객을 연락하다", + "need_help": "질문&도움", + "need_help2": "고객센터", "need_help3": "서비스 효율을 높이기 위해서 아래에 문제가 있으면 숫자를 바로 답장하십시오!", "question1": "【1】아이디 동결된 이유는 무엇입니까 ?", "answer1": " 아래 여러 상황이 나타나면 아이다가 동결될 수 있다 :① 사기꾼 ② 중개 ③ 소란 광고 ④ 많은 사람들이 신고하다 ⑤ 이미 기타 아이디 있다 ⑥ 여러번 위반 방송국 방송의 경고를 무시했다 ⑦ 사용자 스스로 취소 요구", diff --git a/lib/chat/group_chat_item.dart b/lib/chat/group_chat_item.dart index 72dc2ce..53581e9 100644 --- a/lib/chat/group_chat_item.dart +++ b/lib/chat/group_chat_item.dart @@ -840,7 +840,7 @@ class _GroupChatPageItemState 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, diff --git a/lib/chat/group_chat_view.dart b/lib/chat/group_chat_view.dart index 7225f02..8d6a1ff 100644 --- a/lib/chat/group_chat_view.dart +++ b/lib/chat/group_chat_view.dart @@ -495,6 +495,7 @@ class _GroupChatPageState extends State { itemPositionsListener: itemPositionListener, padding: EdgeInsets.all(8.0), reverse: true, + hitCallback: hideKeyBoard, )), ); }