From b3ca32e88fcbcd8213d61342bb63d166181911dd Mon Sep 17 00:00:00 2001 From: wurong <953969641@qq.com> Date: Thu, 19 Sep 2024 18:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E8=81=8A=E5=A4=A9=E6=A1=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=94=B9=EF=BC=9B=20=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=9B=B4=E6=94=B9=EF=BC=9B=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=90=9C=E7=B4=A2=E9=A1=B5=E9=9D=A2=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/im/add_friend.dart | 71 ++++++------- lib/im/chat_details_page.dart | 51 ++++----- lib/im/im_search.dart | 111 ++++++++++++++++++++ lib/im/im_view/friend_groip_list.dart | 144 ++++++++++++-------------- lib/im/im_view/im_page.dart | 89 +++++++--------- lib/main.dart | 3 + lib/mine/personal_page.dart | 13 ++- 7 files changed, 287 insertions(+), 195 deletions(-) diff --git a/lib/im/add_friend.dart b/lib/im/add_friend.dart index 71ca7307..3c01e717 100644 --- a/lib/im/add_friend.dart +++ b/lib/im/add_friend.dart @@ -18,8 +18,6 @@ class AddFriend extends StatefulWidget { class _AddFriend extends State { ApiService apiService; - final TextEditingController editingController = TextEditingController(); - FocusNode _focusNode = FocusNode(); @override void initState() { @@ -29,7 +27,6 @@ class _AddFriend extends State { ///离开页面记着销毁和清除 @override void dispose() { - _focusNode.unfocus(); super.dispose(); } @@ -70,7 +67,7 @@ class _AddFriend extends State { ) ], ),), - friendGroupSearch(), + addFriendSearch(), Padding( padding: EdgeInsets.only(left:18.w,bottom: 16.h), child: Text( @@ -250,42 +247,38 @@ class _AddFriend extends State { } /// 搜索框 - Widget friendGroupSearch() { - return Container( - margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w,29.h), - padding: EdgeInsets.symmetric(vertical: 13.h), - decoration: BoxDecoration( - color: Color(0xFFFDFCFC), - borderRadius: BorderRadius.circular(4), - ), - child: TextField( - textInputAction: TextInputAction.search, - onEditingComplete: () { - FocusScope.of(context).requestFocus(FocusNode()); - }, - controller: editingController, - style: TextStyle( - fontSize: 14.sp, - ), - decoration: InputDecoration( - hintText: "搜索", - hintStyle: TextStyle( - fontSize: 14.sp, - color: Color(0xFFA29E9E), - ), - isCollapsed: true, - prefixIcon: Padding( - padding: EdgeInsets.only(left: 15.w, right: 5.w), - child: Image.asset( - "assets/image/icon_search.webp", - width: 14.h, - height: 14.h, - color: Color(0xFFB3B3B3), - ), + Widget addFriendSearch() { + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap:(){Navigator.of(context).pushNamed('/router/im_search');}, + child: Container( + margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), + padding: EdgeInsets.symmetric(vertical: 13.h), + decoration: BoxDecoration( + color: Color(0xFFFDFCFC), + borderRadius: BorderRadius.circular(4), ), - prefixIconConstraints: BoxConstraints(), - border: InputBorder.none, - ), + child: Row( + children: [ + Padding( + padding: EdgeInsets.only(left: 15.w, right: 5.w), + child: Image.asset( + "assets/image/icon_search.webp", + width: 14.h, + height: 14.h, + color: Color(0xFF353535), + ), + ), + Text( + "搜索", + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize: 16.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ], + ) ), ); } diff --git a/lib/im/chat_details_page.dart b/lib/im/chat_details_page.dart index 05b8c9b5..da5ca5b2 100644 --- a/lib/im/chat_details_page.dart +++ b/lib/im/chat_details_page.dart @@ -18,6 +18,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import '../../community/release_dynamic.dart'; import '../../generated/l10n.dart'; import '../../utils/font_weight.dart'; +import '../view_widget/custom_image.dart'; import 'im_view/on_chat_message.dart'; import 'im_view/on_chat_msg_instance.dart'; @@ -155,9 +156,8 @@ class _ChatDetailsPage extends State OnChatMsgInstance.instance.onChatMessage = _tempOnChatMessage; WidgetsBinding.instance.removeObserver(this); commentFocus.removeListener(_focusNodeListener); - + scrollController.dispose(); socketClient.removeCallback(_toUser.mid); - } void _focusNodeListener() { @@ -252,7 +252,7 @@ class _ChatDetailsPage extends State // resizeToAvoidBottomInset: false, backgroundColor: Color(0xFFF6F6F6), appBar: MyAppBar( - title: "哈哈哈哈", + title: _toUser.nickname, titleColor: Color(0xFF0D0D0D), titleSize: 17.sp, leading: true, @@ -453,24 +453,19 @@ class _ChatDetailsPage extends State ), /// not self - if (!isSelf && isText) + if (!isSelf && !isText) Padding( padding: EdgeInsets.only(left: 17.w, right: 39.w), child: Row( children: [ - // MImage( - // "", - // isCircle: true, - // width: 44, - // height: 44, - // fit: BoxFit.cover, - // errorSrc: "assets/image/default_user.webp", - // fadeSrc: "assets/image/default_user.webp", - // ), - Image.asset( - "assets/image/fuka_zj.webp", + MImage( + _toUser.avatar, + isCircle: true, height: 44.h, width: 44.h, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.webp", + fadeSrc: "assets/image/default_1.webp", ), SizedBox( width: 12.w, @@ -660,25 +655,25 @@ class _ChatDetailsPage extends State SizedBox( width: 12.w, ), - // MImage( - // "", - // isCircle: true, - // width: 44, + MImage( + _toUser.avatar, + isCircle: true, + height: 44.h, + width: 44.h, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.webp", + fadeSrc: "assets/image/default_1.webp", + ), + // Image.asset( + // "assets/image/fuka_zj.webp", // height: 44, - // fit: BoxFit.cover, - // errorSrc: "assets/image/default_user.webp", - // fadeSrc: "assets/image/default_user.webp", + // width: 44, // ), - Image.asset( - "assets/image/fuka_zj.webp", - height: 44, - width: 44, - ), ], ), ), - /// not self image + /// not self image 图片 if (!isSelf && !isText) Padding( padding: EdgeInsets.only(left: 17.w, right: 39.w, top: 20.h), diff --git a/lib/im/im_search.dart b/lib/im/im_search.dart index e69de29b..47205b71 100644 --- a/lib/im/im_search.dart +++ b/lib/im/im_search.dart @@ -0,0 +1,111 @@ +import 'dart:ui'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +import '../retrofit/retrofit_api.dart'; +import '../view_widget/my_appbar.dart'; + + +class ImSearch extends StatefulWidget { + @override + State createState() { + return _ImSearch(); + } +} + +class _ImSearch extends State { + ApiService apiService; + final TextEditingController editingController = TextEditingController(); + FocusNode _focusNode = FocusNode(); + + @override + void initState() { + super.initState(); + } + + ///离开页面记着销毁和清除 + @override + void dispose() { + _focusNode.unfocus(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap:(){ + FocusScope.of(context).requestFocus(FocusNode()); + }, + child: Scaffold( + backgroundColor: Color(0xFFFFFFFF), + resizeToAvoidBottomInset: false, + appBar: MyAppBar( + title: "", + leading: true, + leadingColor: Colors.black, + background: Color(0xFFFFFFFF), + ), + body: Container( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + imSearch(), + // Expanded( + // child: ListView.builder( + // itemCount: 10, + // physics: BouncingScrollPhysics(), + // shrinkWrap: true, + // itemBuilder: (context, position) { + // return imSearch(); + // }, + // )), + ], + ), + ), + ), + ); + } + + ///搜索列表 + Widget imSearch() { + return Container( + margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w,29.h), + padding: EdgeInsets.symmetric(vertical: 13.h), + decoration: BoxDecoration( + color: Color(0xFFFDFCFC), + borderRadius: BorderRadius.circular(4), + ), + child: TextField( + textInputAction: TextInputAction.search, + onEditingComplete: () { + FocusScope.of(context).requestFocus(FocusNode()); + }, + controller: editingController, + style: TextStyle( + fontSize: 14.sp, + ), + decoration: InputDecoration( + hintText: "搜索", + hintStyle: TextStyle( + fontSize: 14.sp, + color: Color(0xFFA29E9E), + ), + isCollapsed: true, + prefixIcon: Padding( + padding: EdgeInsets.only(left: 15.w, right: 5.w), + child: Image.asset( + "assets/image/icon_search.webp", + width: 14.h, + height: 14.h, + color: Color(0xFFB3B3B3), + ), + ), + prefixIconConstraints: BoxConstraints(), + border: InputBorder.none, + ), + ), + ); + } +} diff --git a/lib/im/im_view/friend_groip_list.dart b/lib/im/im_view/friend_groip_list.dart index cfdbfed8..cb4b342f 100644 --- a/lib/im/im_view/friend_groip_list.dart +++ b/lib/im/im_view/friend_groip_list.dart @@ -2,6 +2,7 @@ import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:huixiang/retrofit/data/im_user.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../../retrofit/data/base_data.dart'; @@ -10,6 +11,7 @@ import '../../retrofit/data/page.dart'; import '../../retrofit/retrofit_api.dart'; import 'package:huixiang/im/database/message.dart'; +import '../../utils/font_weight.dart'; import '../../view_widget/custom_image.dart'; import '../../view_widget/no_data_view.dart'; @@ -17,9 +19,7 @@ class FriendGroupList extends StatefulWidget { final String isMyFans; final String title; - FriendGroupList( - Key key,this.isMyFans,this.title - ) : super(key: key); + FriendGroupList(Key key, this.isMyFans, this.title) : super(key: key); @override State createState() { @@ -29,9 +29,7 @@ class FriendGroupList extends StatefulWidget { class _FriendGroupList extends State { ApiService apiService; - final TextEditingController editingController = TextEditingController(); RefreshController _refreshController; - FocusNode _focusNode = FocusNode(); List userIds = []; List messages = []; int pageNum = 1; @@ -41,9 +39,9 @@ class _FriendGroupList extends State { void initState() { super.initState(); // loadMessageList(); - if( widget.isMyFans == ""){ + if (widget.isMyFans == "") { queryMutualFollowList(); - } else{ + } else { queryFollowList(); } } @@ -51,7 +49,6 @@ class _FriendGroupList extends State { ///离开页面记着销毁和清除 @override void dispose() { - _focusNode.unfocus(); super.dispose(); } @@ -95,14 +92,11 @@ class _FriendGroupList extends State { list.clear(); } list.addAll(baseData.data.list); - if(!mounted) - return; + if (!mounted) return; setState(() {}); } } - - ///好友列表 queryMutualFollowList() async { SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); @@ -126,8 +120,7 @@ class _FriendGroupList extends State { list.clear(); } list.addAll(baseData.data.list); - if(!mounted) - return; + if (!mounted) return; setState(() {}); } } @@ -141,32 +134,37 @@ class _FriendGroupList extends State { friendGroupSearch(), (list == null || list.length == 0) ? NoDataView( - src: "assets/image/guan_zhu.webp", - isShowBtn: false, - text: widget.title == "好友"?"目前暂无${widget?.title ?? ""}":("目前暂无${widget?.title ?? ""},${widget?.title == "粉丝" ? - "听说多发动态可以涨粉哦" :"可以在社群广场中关注自己喜欢的人哦"}~"), - fontSize: 16.sp, - margin: EdgeInsets.only(top: 120.h,left: 60.w,right: 60.w), - ):Expanded( - child: ListView.builder( - itemCount: list.length ?? 0, - physics: BouncingScrollPhysics(), - shrinkWrap: true, - itemBuilder: (context, position) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap:(){ - Navigator.of(context).pushNamed( - '/router/chat_details_page', - arguments: { - "toId":list[position].mid, - }, - ); - }, - child:friendGroupItem(list[position]), - ); - }, - )), + src: "assets/image/guan_zhu.webp", + isShowBtn: false, + text: widget.title == "好友" + ? "目前暂无${widget?.title ?? ""}" + : ("目前暂无${widget?.title ?? ""},${widget?.title == "粉丝" ? "听说多发动态可以涨粉哦" : "可以在社群广场中关注自己喜欢的人哦"}~"), + fontSize: 16.sp, + margin: EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w), + ) + : Expanded( + child: ListView.builder( + itemCount: list.length ?? 0, + physics: BouncingScrollPhysics(), + shrinkWrap: true, + itemBuilder: (context, position) { + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + Navigator.of(context).pushNamed( + '/router/chat_details_page', + arguments: { + "toUser": ImUser( + avatar: list[position].avatar, + mid: list[position].mid, + nickname: list[position].nickname), + }, + ); + }, + child: friendGroupItem(list[position]), + ); + }, + )), ], ), ); @@ -174,7 +172,7 @@ class _FriendGroupList extends State { Widget friendGroupItem(ListData list) { return Container( - margin: EdgeInsets.only(left:16.w,right:16.w,bottom: 24.h), + margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 24.h), child: Row(children: [ Container( decoration: BoxDecoration( @@ -206,41 +204,37 @@ class _FriendGroupList extends State { /// 搜索框 Widget friendGroupSearch() { - return Container( - margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w,24.h), - padding: EdgeInsets.symmetric(vertical: 13.h), - decoration: BoxDecoration( - color: Color(0xFFFDFCFC), - borderRadius: BorderRadius.circular(4), - ), - child: TextField( - textInputAction: TextInputAction.search, - onEditingComplete: () { - FocusScope.of(context).requestFocus(FocusNode()); - }, - controller: editingController, - style: TextStyle( - fontSize: 14.sp, - ), - decoration: InputDecoration( - hintText: "搜索", - hintStyle: TextStyle( - fontSize: 14.sp, - color: Color(0xFFA29E9E), - ), - isCollapsed: true, - prefixIcon: Padding( - padding: EdgeInsets.only(left: 15.w, right: 5.w), - child: Image.asset( - "assets/image/icon_search.webp", - width: 14.h, - height: 14.h, - color: Color(0xFFB3B3B3), - ), + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap:(){Navigator.of(context).pushNamed('/router/im_search');}, + child: Container( + margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), + padding: EdgeInsets.symmetric(vertical: 13.h), + decoration: BoxDecoration( + color: Color(0xFFFDFCFC), + borderRadius: BorderRadius.circular(4), ), - prefixIconConstraints: BoxConstraints(), - border: InputBorder.none, - ), + child: Row( + children: [ + Padding( + padding: EdgeInsets.only(left: 15.w, right: 5.w), + child: Image.asset( + "assets/image/icon_search.webp", + width: 14.h, + height: 14.h, + color: Color(0xFF353535), + ), + ), + Text( + "搜索", + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize: 16.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ], + ) ), ); } diff --git a/lib/im/im_view/im_page.dart b/lib/im/im_view/im_page.dart index 455c2432..322924ff 100644 --- a/lib/im/im_view/im_page.dart +++ b/lib/im/im_view/im_page.dart @@ -51,7 +51,10 @@ class _IMPage extends State implements OnChatMessage { "6": 0, }; int state = 0; - final TextEditingController imEditingController = TextEditingController(); + List userIds = []; + Map lastMessageMap = {}; + Map unreadCountMap = {}; + Map contactMap = {}; @override void onMessage(txt) { @@ -85,11 +88,6 @@ class _IMPage extends State implements OnChatMessage { queryMsgStats(); } - List userIds = []; - Map lastMessageMap = {}; - Map unreadCountMap = {}; - Map contactMap = {}; - loadMessageList() async { SharedPreferences shared = await SharedPreferences.getInstance(); String userId = shared.getString("userId"); @@ -124,7 +122,6 @@ class _IMPage extends State implements OnChatMessage { .where((element) => element != userId) .toList(); List contacts = (await hxDatabase.queryImUser(userIds)) ?? []; - unreadCountMap = await hxDatabase.messageUnreadCount(userIds, userId); lastMessageMap = messages.lGroupBy((p0) => p0.toId != userId ? p0.toId : p0.fromId).mGroupItem; @@ -344,7 +341,7 @@ class _IMPage extends State implements OnChatMessage { ], ), ), - imSearchItem(), + imPageSearch(), chatList(), // buildMessage(),fgg ], @@ -357,50 +354,40 @@ class _IMPage extends State implements OnChatMessage { } ///搜索 - Widget imSearchItem() { - return Container( - margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), - padding: EdgeInsets.symmetric(vertical: 13.h), - decoration: BoxDecoration( - color: Color(0xFFFFFFFF), - borderRadius: BorderRadius.circular(4), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, - ), - ], - ), - child: TextField( - textInputAction: TextInputAction.search, - onEditingComplete: () { - FocusScope.of(context).requestFocus(FocusNode()); - }, - controller: imEditingController, - style: TextStyle( - fontSize: 14.sp, - ), - decoration: InputDecoration( - hintText: "搜索", - hintStyle: TextStyle( - fontSize: 14.sp, - color: Color(0xFFA29E9E), - ), - isCollapsed: true, - prefixIcon: Padding( - padding: EdgeInsets.only(left: 15.w, right: 5.w), - child: Image.asset( - "assets/image/icon_search.webp", - width: 14.h, - height: 14.h, - color: Color(0xFF353535), - ), + Widget imPageSearch() { + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap:(){ + Navigator.of(context).pushNamed('/router/im_search'); + }, + child: Container( + margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), + padding: EdgeInsets.symmetric(vertical: 13.h), + decoration: BoxDecoration( + color: Color(0xFFFDFCFC), + borderRadius: BorderRadius.circular(4), ), - prefixIconConstraints: BoxConstraints(), - border: InputBorder.none, - ), + child: Row( + children: [ + Padding( + padding: EdgeInsets.only(left: 15.w, right: 5.w), + child: Image.asset( + "assets/image/icon_search.webp", + width: 14.h, + height: 14.h, + color: Color(0xFF353535), + ), + ), + Text( + "搜索", + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize: 16.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ], + ) ), ); } diff --git a/lib/main.dart b/lib/main.dart index 3eb87255..f3b09399 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -152,6 +152,7 @@ import 'im/chat_details_page.dart'; import 'im/chat_friend_group.dart'; import 'im/chat_setting.dart'; import 'im/contact_share.dart'; +import 'im/im_search.dart'; import 'login/login_store_select.dart'; import 'login/new_login_page.dart'; import 'login/phone_address_page.dart'; @@ -625,5 +626,7 @@ Map routers = { EditInvoicesInfo(arguments:arguments), '/router/invoices_detail_page': (context, {arguments}) => InvoicesDetailPage(arguments:arguments), + '/router/im_search': (context, {arguments}) => + ImSearch(), }; diff --git a/lib/mine/personal_page.dart b/lib/mine/personal_page.dart index 2202e9a6..4ed4873d 100644 --- a/lib/mine/personal_page.dart +++ b/lib/mine/personal_page.dart @@ -26,6 +26,7 @@ import 'package:permission_handler/permission_handler.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../retrofit/data/im_user.dart'; import '../view_widget/my_tab.dart'; class PersonalPage extends StatefulWidget { @@ -862,7 +863,12 @@ class _PersonalPage extends State with WidgetsBindingObserver,Sing behavior: HitTestBehavior.opaque, onTap: () { Navigator.of(context) - .pushNamed('/router/chat_details_page'); + .pushNamed('/router/chat_details_page',arguments:{ + "toUser": ImUser( + avatar: memberInfor?.headimg, + mid: memberInfor?.id, + nickname: memberInfor?.nickname) + }); }, child: Container( padding: @@ -1294,7 +1300,10 @@ class _PersonalPage extends State with WidgetsBindingObserver,Sing onTap: () { Navigator.of(context) .pushNamed('/router/chat_details_page', arguments: { - "toId": memberInfor.id, + "toUser": ImUser( + avatar: memberInfor?.headimg, + mid: memberInfor?.id, + nickname: memberInfor?.nickname) },); },