Browse Source

消息列表删除仿微信更改;

列表新增常规消息通知
wr_202303
wurong 4 months ago
parent
commit
741852b0db
  1. BIN
      assets/image/2x/icon_gz.webp
  2. BIN
      assets/image/2x/icon_pl.webp
  3. BIN
      assets/image/2x/icon_system_message_new.webp
  4. BIN
      assets/image/2x/icon_z.webp
  5. BIN
      assets/image/3x/icon_gz.webp
  6. BIN
      assets/image/3x/icon_pl.webp
  7. BIN
      assets/image/3x/icon_system_message_new.webp
  8. BIN
      assets/image/3x/icon_z.webp
  9. BIN
      assets/image/icon_gz.webp
  10. BIN
      assets/image/icon_pl.webp
  11. BIN
      assets/image/icon_system_message_new.webp
  12. BIN
      assets/image/icon_z.webp
  13. 309
      lib/im/im_view/im_page.dart
  14. 2
      lib/message/system_message.dart

BIN
assets/image/2x/icon_gz.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
assets/image/2x/icon_pl.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
assets/image/2x/icon_system_message_new.webp

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
assets/image/2x/icon_z.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
assets/image/3x/icon_gz.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
assets/image/3x/icon_pl.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
assets/image/3x/icon_system_message_new.webp

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
assets/image/3x/icon_z.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
assets/image/icon_gz.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
assets/image/icon_pl.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 762 B

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/image/icon_system_message_new.webp

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
assets/image/icon_z.webp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 806 B

After

Width:  |  Height:  |  Size: 1.1 KiB

309
lib/im/im_view/im_page.dart

@ -1,10 +1,11 @@
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/constant.dart'; import 'package:huixiang/constant.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/im/database/message.dart'; import 'package:huixiang/im/database/message.dart';
import 'package:huixiang/retrofit/data/msg_stats.dart';
import 'package:huixiang/main.dart'; import 'package:huixiang/main.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart';
@ -16,6 +17,7 @@ import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../retrofit/data/im_user.dart'; import '../../retrofit/data/im_user.dart';
import '../../retrofit/data/page.dart';
import '../../utils/flutter_utils.dart'; import '../../utils/flutter_utils.dart';
import '../../view_widget/custom_image.dart'; import '../../view_widget/custom_image.dart';
import 'on_chat_message.dart'; import 'on_chat_message.dart';
@ -49,6 +51,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
Map<String, ImUser> contactMap = {}; Map<String, ImUser> contactMap = {};
int insertIndex = 0; int insertIndex = 0;
String selfUserId; String selfUserId;
final RefreshController _refreshController = RefreshController();
@override @override
void onMessage(txt) { void onMessage(txt) {
@ -72,7 +75,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
SharedPreferences.getInstance().then((value) { SharedPreferences.getInstance().then((value) {
apiService = ApiService(Dio(), token: value.getString("token"), context: context); apiService = ApiService(Dio(), token: value.getString("token"), context: context);
// queryMsgStats(); queryMsgStats();
}); });
} }
@ -96,7 +99,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
_refresh() { _refresh() {
pageNum = 1; pageNum = 1;
loadMessageList(); loadMessageList();
// queryMsgStats(); queryMsgStats();
} }
listenerRefresh(Message message) async { listenerRefresh(Message message) async {
@ -218,7 +221,34 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
} }
} }
final RefreshController _refreshController = RefreshController(); ///App消息
queryMsgStats() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
BaseData<List<MsgStats>> baseData =
await apiService.stats().catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
setState(() {
msgNumber.forEach((key, value) {
msgNumber[key] = 0;
});
baseData.data.forEach((element) {
if (msgNumber.containsKey(element.name)) {
msgNumber[element.name] = element.number;
}
});
});
_refreshController.loadComplete();
_refreshController.refreshCompleted();
}
EasyLoading.dismiss();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -305,7 +335,56 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
), ),
), ),
imPageSearch(), 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(), chatList(),
SizedBox(height:100.h)
], ],
), ),
), ),
@ -324,7 +403,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
}); });
}, },
child: Container( child: Container(
margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 16.h),
padding: EdgeInsets.symmetric(vertical: 13.h), padding: EdgeInsets.symmetric(vertical: 13.h),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Color(0xFFFDFCFC), color: Color(0xFFFDFCFC),
@ -355,67 +434,116 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
); );
} }
bool _isDelEnter = false;
Map<String, ScrollController> idsController = {};
String lastScrollId;
double lastScrollOffset = 0;
bool _isScrollOpen = false;
/// ///
Widget chatList() { Widget chatList() {
return Container( return ListView(
child: SlidableAutoCloseBehavior( padding: EdgeInsets.only(top:8.h),
child: ListView( shrinkWrap: true,
padding: EdgeInsets.only(top: 16), physics: NeverScrollableScrollPhysics(),
shrinkWrap: true, children: conversationIds.map((e) {
physics: NeverScrollableScrollPhysics(), ScrollController scrollController;
children: conversationIds.map((e) { if (idsController.containsKey(e))
int position = conversationIds.indexOf(e); scrollController = idsController[e];
return ClipRRect( else {
// borderRadius: BorderRadius.all(Radius.circular(4)), scrollController = ScrollController();
child: Slidable( idsController[e] = scrollController;
groupTag: true, }
endActionPane: ActionPane( scrollController.addListener(() {
extentRatio:0.16, if (scrollController.offset > 0) {
motion: ScrollMotion(), if (lastScrollId != null && lastScrollId != e)
children: [ idsController[lastScrollId].jumpTo(0);
CustomSlidableAction( if(lastScrollOffset < scrollController.offset){
onPressed: (bc) { scrollController.jumpTo(scrollController.position.maxScrollExtent);
showDelDialog(conversationIds[position]); _isScrollOpen = true;
}, }else if(lastScrollOffset > scrollController.offset && _isScrollOpen){
backgroundColor: Color(0xFFFB312B), scrollController.jumpTo(0);
foregroundColor: Colors.white, }
child: Container( lastScrollId = e;
color: Colors.red, // scrollController.animateTo(
height: double.infinity, // lastScrollOffset == scrollController.position.maxScrollExtent
alignment: Alignment.center, // ? 0
child: Text( // : scrollController.position.maxScrollExtent,
S.of(context).shanchu, // duration: Duration(milliseconds: 100),
style: TextStyle( // curve: Curves.ease);
color: Colors.white, lastScrollOffset = scrollController.offset;
fontSize: 14.sp, } else {
fontWeight: MyFontWeight.regular, if (lastScrollId == e) {
), setState(() {
), _isDelEnter = false;
), _isScrollOpen = false;
});
}
}
});
int position = conversationIds.indexOf(e);
return SingleChildScrollView(
physics: ClampingScrollPhysics(),
controller: scrollController,
scrollDirection: Axis.horizontal,
child: Row(
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(
'/router/chat_details_page',
arguments: {
"toUser": contactMap[conversationIds[position]],
},
).then((value) {
unreadCountMap[conversationIds[position]] = 0;
updateLastMessage(conversationIds[position]);
_refresh();
});
},
child: chatItem(conversationIds[position]),
),
GestureDetector(
child: Container(
color: Colors.red,
alignment: Alignment.center,
padding:
EdgeInsets.symmetric(vertical: 25.h, horizontal: 14.w),
child: Text(
_isDelEnter && lastScrollId == e
? "删除并清空"
: S.of(context).shanchu,
style: TextStyle(
color: Colors.white,
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
), ),
], ),
), ),
child: GestureDetector( onTap: () async{
behavior: HitTestBehavior.opaque, // showDelDialog(conversationIds[position]);
onTap: () { if (_isDelEnter) {
Navigator.of(context).pushNamed( await hxDatabase.deleteByUser(conversationIds[position]);
'/router/chat_details_page', lastScrollId = null;
arguments: { _refresh();
"toUser": contactMap[conversationIds[position]], } else {
}, Future.delayed(Duration(milliseconds: 100), () {
).then((value) { idsController[lastScrollId].animateTo(
unreadCountMap[conversationIds[position]] = 0; idsController[lastScrollId].position.maxScrollExtent,
updateLastMessage(conversationIds[position]); duration: Duration(milliseconds: 100),
_refresh(); curve: Curves.ease);
}); });
}, }
child: chatItem(conversationIds[position]), setState(() {
), _isDelEnter = !_isDelEnter;
});
},
), ),
); ],
}).toList(), ),
), );
), }).toList(),
); );
} }
@ -424,6 +552,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
padding: EdgeInsets.only( 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( child: Row(
children: [ children: [
MImage( MImage(
@ -518,6 +647,66 @@ 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),
child: Column(
children: [
Row(
children: [
Image.asset(
img,
fit: BoxFit.fill,
),
SizedBox(
width: 12.w,
),
Text(
title,
style: TextStyle(
fontSize: 14.sp,
color: Color(0xFF060606),
fontWeight: MyFontWeight.semi_bold,
),
),
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,
))),
],
),
],
),
);
}
/// ///
showDelDialog(conversationId) { showDelDialog(conversationId) {

2
lib/message/system_message.dart

@ -287,7 +287,7 @@ class _SystemMessagePage extends State<SystemMessagePage>{
}); });
}); });
}, },
child:messageItem("assets/image/icon_system_message.webp", S.of(context).xitongxiaoxi, (msgNumber["2"]+msgNumber["3"]).toString()), child:messageItem("assets/image/icon_system_message_new.webp", S.of(context).xitongxiaoxi, (msgNumber["2"]+msgNumber["3"]).toString()),
), ),
// newsSurvey(), // newsSurvey(),
// SizedBox( // SizedBox(

Loading…
Cancel
Save