From a4206f9b9d89f7cc1cb6dc73ffdba3f995571593 Mon Sep 17 00:00:00 2001 From: zsw Date: Wed, 25 Sep 2024 19:11:10 +0800 Subject: [PATCH] chat add conversation ,database query change userId to conversationId --- lib/im/chat_details_page.dart | 306 +++++++++++++++++----------------- 1 file changed, 154 insertions(+), 152 deletions(-) diff --git a/lib/im/chat_details_page.dart b/lib/im/chat_details_page.dart index 26ada32c..3b2684d9 100644 --- a/lib/im/chat_details_page.dart +++ b/lib/im/chat_details_page.dart @@ -67,7 +67,7 @@ class _ChatDetailsPage extends State int copyIndex = 0; String selfUserId = ""; ImUser _toUser; - String conversation ; + String conversation; @override void onMessage(txt) { @@ -124,7 +124,8 @@ class _ChatDetailsPage extends State Future messageShowTime() async { List messagePages = await hxDatabase.queryTList(conversation); for (var value in messages) { - Message message = messagePages.firstWhere((element) => value.id == element.id, orElse: () => null); + Message message = messagePages + .firstWhere((element) => value.id == element.id, orElse: () => null); value.showTime = message != null; } } @@ -142,8 +143,10 @@ class _ChatDetailsPage extends State } } if (apiService == null) - apiService = ApiService(Dio(), context: context, token: value.getString("token")); - BaseData baseData = await apiService.queryInfo().catchError((onError) {}); + apiService = + ApiService(Dio(), context: context, token: value.getString("token")); + BaseData baseData = + await apiService.queryInfo().catchError((onError) {}); if (baseData != null && baseData.isSuccess) { setState(() { userInfo = baseData.data; @@ -323,83 +326,83 @@ class _ChatDetailsPage extends State } } return GestureDetector( - behavior: HitTestBehavior.translucent, - onTap: () { - FocusScope.of(context).requestFocus(FocusNode()); - setState(() { - emojiShowing = false; - isKeyBoardShow = emojiShowing; - moreShow = false; - isKeyBoardShow = moreShow; - }); - }, - child: Scaffold( - // resizeToAvoidBottomInset: false, - backgroundColor: Color(0xFFF6F6F6), - appBar: MyAppBar( - title: _toUser.nickname, - titleColor: Color(0xFF0D0D0D), - titleSize: 17.sp, - leading: true, - leadingColor: Colors.black, - action: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () async { - await Navigator.of(context).pushNamed('/router/chat_setting', - arguments: {"userId": _toUser.mid}); - page = 0; - refresh().then((value) { - refreshState(); - }); - }, - child: Container( - alignment: Alignment.center, - child: Icon( - Icons.more_horiz, - color: Colors.black, - size: 30, - ), + behavior: HitTestBehavior.translucent, + onTap: () { + FocusScope.of(context).requestFocus(FocusNode()); + setState(() { + emojiShowing = false; + isKeyBoardShow = emojiShowing; + moreShow = false; + isKeyBoardShow = moreShow; + }); + }, + child: Scaffold( + // resizeToAvoidBottomInset: false, + backgroundColor: Color(0xFFF6F6F6), + appBar: MyAppBar( + title: _toUser.nickname, + titleColor: Color(0xFF0D0D0D), + titleSize: 17.sp, + leading: true, + leadingColor: Colors.black, + action: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () async { + await Navigator.of(context).pushNamed('/router/chat_setting', + arguments: {"userId": _toUser.mid}); + page = 0; + refresh().then((value) { + refreshState(); + }); + }, + child: Container( + alignment: Alignment.center, + child: Icon( + Icons.more_horiz, + color: Colors.black, + size: 30, ), ), ), - body: Container( - child: Column( - children: [ - Expanded( - child: SmartRefresher( - enablePullDown: false, - enablePullUp: true, - header: MyHeader(), - reverse: true, - physics: BouncingScrollPhysics(), - footer: CustomFooter( - loadStyle: LoadStyle.ShowWhenLoading, - builder: (BuildContext context, LoadStatus mode) { - return SizedBox(); - }, - ), - controller: refreshController, - onLoading: () { - refresh().then((value) { - refreshState(); - }); + ), + body: Container( + child: Column( + children: [ + Expanded( + child: SmartRefresher( + enablePullDown: false, + enablePullUp: true, + header: MyHeader(), + reverse: true, + physics: BouncingScrollPhysics(), + footer: CustomFooter( + loadStyle: LoadStyle.ShowWhenLoading, + builder: (BuildContext context, LoadStatus mode) { + return SizedBox(); }, - child: Container( - alignment: Alignment.topCenter, - child: SingleChildScrollView( - physics: BouncingScrollPhysics(), - controller: scrollController, - child: chatDetailsList(), - ), + ), + controller: refreshController, + onLoading: () { + refresh().then((value) { + refreshState(); + }); + }, + child: Container( + alignment: Alignment.topCenter, + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + controller: scrollController, + child: chatDetailsList(), ), ), - flex: 1, ), - input() - ], - ), + flex: 1, + ), + input() + ], ), ), + ), ); } @@ -444,12 +447,12 @@ class _ChatDetailsPage extends State // position == messages.length-1 // ? AppUtils.milliTimeFormatter(DateTime.fromMillisecondsSinceEpoch( - int.parse(messages[position].time))) - // : AppUtils.getTimeDisplay( - // DateTime.fromMillisecondsSinceEpoch( - // int.parse(messages[position].time)), - // DateTime.fromMillisecondsSinceEpoch( - // int.parse(messages[position+1].time))) + int.parse(messages[position].time))) + // : AppUtils.getTimeDisplay( + // DateTime.fromMillisecondsSinceEpoch( + // int.parse(messages[position].time)), + // DateTime.fromMillisecondsSinceEpoch( + // int.parse(messages[position+1].time))) , textAlign: TextAlign.center, style: TextStyle( @@ -1139,84 +1142,83 @@ class _ChatDetailsPage extends State context: context, builder: (BuildContext context) { return AlertDialog( - // backgroundColor: Color(0xFF2A2A2A), - // elevation: 0, - contentPadding: EdgeInsets.only( - top: 8.h, - bottom: 5.h, - ), - content: Container( - width: 160.w, - height:50.h, - decoration: BoxDecoration( - color: Color(0xFF2A2A2A), - borderRadius: BorderRadius.circular(6), - ), - padding: EdgeInsets.symmetric( - horizontal: 32.w, - vertical: 7.5.h, + // backgroundColor: Color(0xFF2A2A2A), + // elevation: 0, + contentPadding: EdgeInsets.only( + top: 8.h, + bottom: 5.h, ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - GestureDetector( - onTap: () { - setState(() { - copyIndex = 0; - this.copy(tex); - }); - }, - child: Column( - children: [ - Image.asset( - "assets/image/icon_chat_copy.webp", - height: 16, - width: 16, - ), - SizedBox( - height: 2.h, - ), - Text( - "复制", - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.white, - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, + content: Container( + width: 160.w, + height: 50.h, + decoration: BoxDecoration( + color: Color(0xFF2A2A2A), + borderRadius: BorderRadius.circular(6), + ), + padding: EdgeInsets.symmetric( + horizontal: 32.w, + vertical: 7.5.h, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + GestureDetector( + onTap: () { + setState(() { + copyIndex = 0; + this.copy(tex); + }); + }, + child: Column( + children: [ + Image.asset( + "assets/image/icon_chat_copy.webp", + height: 16, + width: 16, ), - ), - ], - ), - ), - GestureDetector( - onTap: () {}, - child: Column( - children: [ - Image.asset( - "assets/image/icon_chat_delete.webp", - height: 16, - width: 16, - ), - SizedBox( - height: 2.h, - ), - Text( - S.of(context).shanchu, - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.white, - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, + SizedBox( + height: 2.h, ), - ), - ], + Text( + "复制", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.white, + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ], + ), ), - ) - ], - ), - ) - ); + GestureDetector( + onTap: () {}, + child: Column( + children: [ + Image.asset( + "assets/image/icon_chat_delete.webp", + height: 16, + width: 16, + ), + SizedBox( + height: 2.h, + ), + Text( + S.of(context).shanchu, + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.white, + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ], + ), + ) + ], + ), + )); }); }