Browse Source

change convasion refresh range

wr_202303
zsw 4 months ago
parent
commit
5441937532
  1. 3
      lib/im/SocketClient.dart
  2. 19
      lib/im/chat_details_page.dart
  3. 425
      lib/im/im_view/im_page.dart
  4. 1
      lib/view_widget/classic_header.dart

3
lib/im/SocketClient.dart

@ -209,7 +209,6 @@ class SocketClient {
}
Future<Message> sendMessage(String toId, String content, {String attach, int msgType = 1, replyId}) async {
MsgType type = MsgType.values[msgType];
Uint8List data;
if (type == MsgType.TEXT) {
@ -254,8 +253,6 @@ class SocketClient {
return Message.fromJson(message);
}
checkSocket() {
if (_socket == null) {
reconnect();

19
lib/im/chat_details_page.dart

@ -422,8 +422,14 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
onTap: () {
setState(() {
copyIndex = 0;
FocusScope.of(context).requestFocus(FocusNode());
if (emojiShowing) {
emojiShowing = !emojiShowing;
}
if (moreShow) {
moreShow = !moreShow;
}
});
FocusScope.of(context).requestFocus(FocusNode());
},
child: chatDetailsItem(position),
);
@ -573,6 +579,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
padding: EdgeInsets.only(left: 17.w, right: 39.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
@ -735,6 +742,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
padding: EdgeInsets.only(left: 36.w, right: 16.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (messages[position].state == 3)
Container(
@ -806,8 +814,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed('/router/personal_page',
arguments: {"memberId": "0", "inletType": 1});
Navigator.of(context).pushNamed(
'/router/personal_page',
arguments: {
"memberId": "0",
"inletType": 1,
},
);
},
child: MImage(
userInfo?.headimg ?? "",

425
lib/im/im_view/im_page.dart

@ -74,7 +74,8 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
initSocketClient();
SharedPreferences.getInstance().then((value) {
apiService = ApiService(Dio(), token: value.getString("token"), context: context);
apiService =
ApiService(Dio(), token: value.getString("token"), context: context);
queryMsgStats();
});
}
@ -118,9 +119,12 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
loadMessageList() async {
messages = await hxDatabase.queryList();
lastMessageMap = messages.lGroupBy((p0) => p0.conversationId).mGroupItem(key: (p1) => num.parse(p1.time));
lastMessageMap = messages
.lGroupBy((p0) => p0.conversationId)
.mGroupItem(key: (p1) => num.parse(p1.time));
await queryImUserInfo(messages.map((e) => e.toId != selfUserId ? e.toId : e.fromId).toList());
await queryImUserInfo(
messages.map((e) => e.toId != selfUserId ? e.toId : e.fromId).toList());
await sortConversation(lastMessageMap);
@ -132,11 +136,10 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
/// update conversation by time sort
sortConversation(lastMessageMap) async {
List<Message> sortMessages = lastMessageMap.values.toList();
sortMessages.sort((a, b) => (num.parse(b.time)).compareTo(num.parse(a.time)));
conversationIds = sortMessages
.map((e) => e.conversationId)
.toSet()
.toList();
sortMessages
.sort((a, b) => (num.parse(b.time)).compareTo(num.parse(a.time)));
conversationIds =
sortMessages.map((e) => e.conversationId).toSet().toList();
}
/// update conversation unreadcount
@ -152,16 +155,20 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
await queryMemberInfo(userIds);
return;
} else {
List<String> queryUserIds = userIds.where((u) => contacts.where((c) => c.mid == u).isEmpty).toList();
List<String> queryUserIds = userIds
.where((u) => contacts.where((c) => c.mid == u).isEmpty)
.toList();
if (queryUserIds.isNotEmpty) {
await queryMemberInfo(queryUserIds);
return;
}
}
contactMap = contacts.lGroupBy((p0) => conversationId(p0.mid, selfUserId)).mGroupItem();
List<String> topConversationIds = [],notTopUserIds = [];
contactMap = contacts
.lGroupBy((p0) => conversationId(p0.mid, selfUserId))
.mGroupItem();
List<String> topConversationIds = [], notTopUserIds = [];
contactMap.forEach((key, value) {
if(value.isTop == 1)
if (value.isTop == 1)
topConversationIds.add(key);
else
notTopUserIds.add(key);
@ -173,7 +180,8 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
/// update one conversation last message ,and update conversation sort
void updateLastMessage(String conversationId) async {
Message message = await hxDatabase.lastMessage(conversationId);
debugPrint("lastmessage: $conversationId ${message?.content} ${message?.toJson()}");
debugPrint(
"lastmessage: $conversationId ${message?.content} ${message?.toJson()}");
if (message != null) {
lastMessageMap[conversationId] = message;
await sortConversation(lastMessageMap);
@ -187,7 +195,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
}
refreshState() {
if(_refreshController.isRefresh)_refreshController.refreshCompleted();
if (_refreshController.isRefresh) _refreshController.refreshCompleted();
if (mounted) setState(() {});
}
@ -232,7 +240,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
);
}
BaseData<List<MsgStats>> baseData =
await apiService.stats().catchError((onError) {});
await apiService.stats().catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
setState(() {
msgNumber.forEach((key, value) {
@ -268,126 +276,146 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
stops: [0, 0.2, 0.4, 1],
),
),
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
physics: BouncingScrollPhysics(),
footer: CustomFooter(
loadStyle: LoadStyle.ShowWhenLoading,
builder: (BuildContext context, LoadStatus mode) {
return (messages.length == 0) ? Container() : MyFooter(mode);
},
),
controller: _refreshController,
onRefresh: _refresh,
onLoading: () {
_refresh();
},
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
Container(
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top + 12.h,
bottom: 15.h,
right: 16.w,
left: 16.w,
child: Column(
children: [
Container(
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top + 12.h,
bottom: 15.h,
right: 16.w,
left: 16.w,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Text(
S.of(context).xiaoxi,
style: TextStyle(
color: Colors.black,
fontSize: 18.sp,
fontWeight: MyFontWeight.bold,
),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Text(
S.of(context).xiaoxi,
style: TextStyle(
color: Colors.black,
fontSize: 18.sp,
fontWeight: MyFontWeight.bold,
),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context)
.pushNamed('/router/chat_friend_group')
.then((value) {
_refresh();
});
},
child: Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Color(0xFFFFFFFF),
borderRadius: BorderRadius.circular(20.r),
),
child: Image.asset(
"assets/image/friend_grouping.webp",
fit: BoxFit.fill,
height: 14.h,
width: 14.h,
),
),
),
],
),
),
imPageSearch(),
Expanded(
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
physics: BouncingScrollPhysics(),
footer: CustomFooter(
loadStyle: LoadStyle.ShowWhenLoading,
builder: (BuildContext context, LoadStatus mode) {
return (messages.length == 0)
? Container()
: MyFooter(mode);
},
),
controller: _refreshController,
onRefresh: _refresh,
onLoading: () {
_refresh();
},
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed('/router/chat_friend_group')
Navigator.of(context)
.pushNamed('/router/system_notice')
.then((value) {
_refresh();
setState(() {
msgNumber["2"] = 0;
msgNumber["3"] = 0;
});
});
},
child: Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Color(0xFFFFFFFF),
borderRadius: BorderRadius.circular(20.r),
),
child: Image.asset(
"assets/image/friend_grouping.webp",
fit: BoxFit.fill,
height: 14.h,
width: 14.h,
),
),
child: messageItem(
"assets/image/icon_system_message_new.webp",
S.of(context).xitongxiaoxi,
(msgNumber["2"] + msgNumber["3"]).toString()),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(
'/router/system_details',
arguments: {"msgType": 4}).then((value) {
setState(() {
msgNumber["4"] = 0;
});
});
},
child: messageItem("assets/image/icon_gz.webp",
S.of(context).guanzhu, msgNumber["4"].toString()),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(
'/router/system_details',
arguments: {"msgType": 6}).then((value) {
setState(() {
msgNumber["6"] = 0;
});
});
},
child: messageItem("assets/image/icon_pl.webp",
S.of(context).pinglun, msgNumber["6"].toString()),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(
'/router/system_details',
arguments: {"msgType": 5}).then((value) {
setState(() {
msgNumber["5"] = 0;
});
});
},
child: messageItem("assets/image/icon_z.webp",
S.of(context).dianzan, msgNumber["5"].toString()),
),
chatList(),
SizedBox(height: 100.h)
],
),
),
imPageSearch(),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: (){
Navigator.of(context).pushNamed('/router/system_notice').then((value) {
setState(() {
msgNumber["2"] = 0;
msgNumber["3"] = 0;
});
});
},
child:messageItem("assets/image/icon_system_message_new.webp", S.of(context).xitongxiaoxi, (msgNumber["2"]+msgNumber["3"]).toString()),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: (){
Navigator.of(context).pushNamed('/router/system_details',
arguments: {"msgType": 4}).then((value) {
setState(() {
msgNumber["4"] = 0;
});
});
},
child:messageItem("assets/image/icon_gz.webp", S.of(context).guanzhu,msgNumber["4"].toString()),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: (){
Navigator.of(context).pushNamed('/router/system_details',
arguments: {"msgType": 6}).then((value) {
setState(() {
msgNumber["6"] = 0;
});
});
},
child:messageItem("assets/image/icon_pl.webp", S.of(context).pinglun, msgNumber["6"].toString()),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: (){
Navigator.of(context).pushNamed('/router/system_details',
arguments: {"msgType": 5}).then((value) {
setState(() {
msgNumber["5"] = 0;
});
});
},
child: messageItem("assets/image/icon_z.webp", S.of(context).dianzan, msgNumber["5"].toString()),
),
chatList(),
SizedBox(height:100.h)
],
),
),
),
],
),
),
);
@ -397,7 +425,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Widget imPageSearch() {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap:(){
onTap: () {
Navigator.of(context).pushNamed('/router/im_search').then((value) {
_refresh();
});
@ -429,8 +457,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
),
),
],
)
),
)),
);
}
@ -443,7 +470,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
///
Widget chatList() {
return ListView(
padding: EdgeInsets.only(top:8.h),
padding: EdgeInsets.only(top: 8.h),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: conversationIds.map((e) {
@ -458,10 +485,12 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
if (scrollController.offset > 0) {
if (lastScrollId != null && lastScrollId != e)
idsController[lastScrollId].jumpTo(0);
if(lastScrollOffset < scrollController.offset){
scrollController.jumpTo(scrollController.position.maxScrollExtent);
if (lastScrollOffset < scrollController.offset) {
scrollController
.jumpTo(scrollController.position.maxScrollExtent);
_isScrollOpen = true;
}else if(lastScrollOffset > scrollController.offset && _isScrollOpen){
} else if (lastScrollOffset > scrollController.offset &&
_isScrollOpen) {
scrollController.jumpTo(0);
}
lastScrollId = e;
@ -509,7 +538,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
color: Colors.red,
alignment: Alignment.center,
padding:
EdgeInsets.symmetric(vertical: 25.h, horizontal: 14.w),
EdgeInsets.symmetric(vertical: 25.h, horizontal: 14.w),
child: Text(
_isDelEnter && lastScrollId == e
? "删除并清空"
@ -521,7 +550,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
),
),
),
onTap: () async{
onTap: () async {
// showDelDialog(conversationIds[position]);
if (_isDelEnter) {
await hxDatabase.deleteByUser(conversationIds[position]);
@ -550,7 +579,9 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Widget chatItem(conversationId) {
return Container(
padding: EdgeInsets.only(
left: 16.w, right: 17.w, bottom: 18.h,
left: 16.w,
right: 17.w,
bottom: 18.h,
),
width: MediaQuery.of(context).size.width,
child: Row(
@ -620,7 +651,8 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
),
),
),
if (unreadCountMap[conversationId] != null && unreadCountMap[conversationId] > 0)
if (unreadCountMap[conversationId] != null &&
unreadCountMap[conversationId] > 0)
Container(
width: 16,
height: 16,
@ -649,7 +681,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Widget messageItem(img, title, messageNum) {
return Container(
padding: EdgeInsets.only(top:8.h,bottom:8.h, left:16.w,right:15.w),
padding: EdgeInsets.only(top: 8.h, bottom: 8.h, left: 16.w, right: 15.w),
child: Column(
children: [
Row(
@ -670,37 +702,38 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
),
),
Spacer(),
if(messageNum != "0")
((double.tryParse(messageNum) < 100)?
Container(
width: 16,
height: 16,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xFFFF441A),
),
child: RoundButton(
text:messageNum,
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize: 10.sp,
radius: 100,
)):
Container(
padding: EdgeInsets.symmetric(horizontal:4.w,vertical:2.h),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xFFFF441A),
),
child: RoundButton(
text:"99+",
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize: 10.sp,
radius: 100,
))),
if (messageNum != "0")
((double.tryParse(messageNum) < 100)
? Container(
width: 16,
height: 16,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xFFFF441A),
),
child: RoundButton(
text: messageNum,
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize: 10.sp,
radius: 100,
))
: Container(
padding: EdgeInsets.symmetric(
horizontal: 4.w, vertical: 2.h),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xFFFF441A),
),
child: RoundButton(
text: "99+",
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize: 10.sp,
radius: 100,
))),
],
),
],
@ -725,23 +758,24 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(child:Container(
alignment:Alignment.center,
child: Text(
"删除并清空聊天记录",
style: TextStyle(
color: Color(0xFF060606),
fontSize: 16.sp,
fontWeight: MyFontWeight.bold,
Expanded(
child: Container(
alignment: Alignment.center,
child: Text(
"删除并清空聊天记录",
style: TextStyle(
color: Color(0xFF060606),
fontSize: 16.sp,
fontWeight: MyFontWeight.bold,
),
),
),
),
),
// Spacer(),
Container(
height:1.h,
height: 1.h,
width: double.infinity,
color:Color(0xFFEDEDED),
color: Color(0xFFEDEDED),
),
Row(
children: [
@ -752,38 +786,33 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Navigator.of(context).pop();
},
child: Container(
child: Text(
"取消",
child: Text("取消",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16.sp,
color: Color(0xFF060606),
)
)
)
)
),
))))),
Container(
height:45,
height: 45,
width: 1.w,
color: Color(0xFFEDEDED),
),
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () async{
await hxDatabase.deleteByUser(conversationId);
_refresh();
Navigator.of(context).pop();
},
child: Text(
"确认",
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFFFF370A),
),
),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () async {
await hxDatabase.deleteByUser(conversationId);
_refresh();
Navigator.of(context).pop();
},
child: Text(
"确认",
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFFFF370A),
),
),
),
),
],
)

1
lib/view_widget/classic_header.dart

@ -17,6 +17,7 @@ class MyHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MyClassicHeader(
height: 80,
refreshStyle: RefreshStyle.Follow,
completeText: S.of(context).shuaxinchenggong,
failedText: S.of(context).shuaxinshibai,

Loading…
Cancel
Save