diff --git a/lib/constants/api.dart b/lib/constants/api.dart index cd9cf479..b544b4fd 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -233,4 +233,12 @@ class _Message { ///消息中心:查询所有的系统通知 String get sysMessageList => '/user/message/sysMessageList'; + + + ///消息中心:全部已读 + String get allRead => '/user/message/allRead'; + + ///消息中心:阅读消息(未读 -> 已读) + String get readMessage => '/user/message/readMessage'; + } diff --git a/lib/pages/message_center_page/message_center_page.dart b/lib/pages/message_center_page/message_center_page.dart index 5454d04d..a59d02bb 100644 --- a/lib/pages/message_center_page/message_center_page.dart +++ b/lib/pages/message_center_page/message_center_page.dart @@ -1,10 +1,13 @@ +import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/pages/message_center_page/system_message/system_message_page.dart'; import 'package:akuCommunity/provider/app_provider.dart'; +import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/widget/buttons/column_action_button.dart'; import 'package:badges/badges.dart'; import 'package:flutter/material.dart'; import 'package:akuCommunity/utils/headers.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:provider/provider.dart'; class MessageCenterPage extends StatefulWidget { @@ -15,6 +18,19 @@ class MessageCenterPage extends StatefulWidget { } class _MessageCenterPageState extends State { + EasyRefreshController _refreshController; + @override + void initState() { + super.initState(); + _refreshController = EasyRefreshController(); + } + + @override + void dispose() { + _refreshController?.dispose(); + super.dispose(); + } + Widget _buildCard({ String path, String title, @@ -43,7 +59,7 @@ class _MessageCenterPageState extends State { children: [ title.text.black.bold.size(32.sp).make(), 5.w.heightBox, - content.text.black.size(28.sp).make(), + (content).text.black.size(28.sp).make(), ], ).expand() ], @@ -59,33 +75,45 @@ class _MessageCenterPageState extends State { title: '消息中心', actions: [ MaterialButton( - onPressed: () {}, + onPressed: () async { + await NetUtil().dio.get(API.message.allRead); + _refreshController.callRefresh(); + setState(() {}); + }, child: '全部已读'.text.size(28.sp).black.make(), padding: EdgeInsets.symmetric(horizontal: 32.w), ), ], - body: Column( - children: [ - _buildCard( - path: R.ASSETS_ICONS_SYSTEM_NOTICE_PNG, - title: '系统通知', - content: appProvider.messageCenterModel.sysTitle, - count: appProvider.messageCenterModel.sysCount, - onTap: SystemMessagePage().to, - ), - _buildCard( - path: R.ASSETS_ICONS_COMMENT_NOTICE_PNG, - title: '评论通知', - content: appProvider.messageCenterModel.commentTitle, - count: appProvider.messageCenterModel.commentCount, - ), - // _buildCard( - // path: R.ASSETS_ICONS_SHOP_NOTICE_PNG, - // title: '商城通知', - // content: '', - // count: 0, - // ) - ], + body: EasyRefresh( + header: MaterialHeader(), + firstRefresh: true, + onRefresh: () async { + appProvider.getMessageCenter(); + }, + child: Column( + children: [ + _buildCard( + path: R.ASSETS_ICONS_SYSTEM_NOTICE_PNG, + title: '系统通知', + content: appProvider.messageCenterModel.sysTitle ?? '无系统通知消息', + count: appProvider.messageCenterModel.sysCount ?? 0, + onTap: SystemMessagePage().to, + ), + _buildCard( + path: R.ASSETS_ICONS_COMMENT_NOTICE_PNG, + title: '评论通知', + content: + appProvider.messageCenterModel.commentTitle ?? '无评论通知消息', + count: appProvider.messageCenterModel.commentCount ?? 0, + ), + // _buildCard( + // path: R.ASSETS_ICONS_SHOP_NOTICE_PNG, + // title: '商城通知', + // content: '', + // count: 0, + // ) + ], + ), )); } } diff --git a/lib/utils/bee_map.dart b/lib/utils/bee_map.dart index 33b0f7e3..7690d836 100644 --- a/lib/utils/bee_map.dart +++ b/lib/utils/bee_map.dart @@ -53,6 +53,6 @@ class BeeMap { static Map messageIsRead ={ 1:false, - 2:true, + 3:true, }; }