From 0ed31f49fdbafe8776f4b5dcfe41c2c24e83db98 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 10 May 2021 11:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B6=88=E6=81=AF=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main_initialize.dart | 6 +++++ lib/pages/home/home_page.dart | 10 ++++--- .../message_center_page.dart | 22 +++++++++------- lib/provider/user_provider.dart | 2 ++ .../community_views/community_page.dart | 26 ++++++++++++++----- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/lib/main_initialize.dart b/lib/main_initialize.dart index c2b91288..6f3144ed 100644 --- a/lib/main_initialize.dart +++ b/lib/main_initialize.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:aku_community/provider/app_provider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -8,12 +9,14 @@ import 'package:flutter/services.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:fluwx/fluwx.dart'; +import 'package:get/get.dart'; import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:power_logger/power_logger.dart'; import 'package:aku_community/constants/app_theme.dart'; import 'package:aku_community/constants/config.dart'; import 'package:aku_community/utils/message_parser.dart'; +import 'package:provider/provider.dart'; class MainInitialize { ///初始化firebase @@ -52,6 +55,9 @@ class MainInitialize { onReceiveNotification: (message) async { LoggerData.addData(message, tag: 'onReceiveNotification'); await MessageParser(message).shot(); + final appProvider = + Provider.of(Get.context!, listen: false); + appProvider.getMessageCenter(); }, onOpenNotification: jPushLogger('onOpenNotification'), onReceiveMessage: jPushLogger('onReceiveMessage'), diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index c626658a..3a8196de 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -69,8 +69,12 @@ class _HomePageState extends State actions: [ Badge( elevation: 0, - showBadge: appProvider.messageCenterModel.sysCount == 0, - position: BadgePosition.topEnd(), + showBadge: appProvider.messageCenterModel.commentCount != 0 || + appProvider.messageCenterModel.sysCount != 0, + position: BadgePosition.topEnd( + top: 8, + end: 8, + ), child: ColumnActionButton( onPressed: () { if (LoginUtil.isNotLogin) return; @@ -79,7 +83,7 @@ class _HomePageState extends State title: '消息', path: R.ASSETS_ICONS_ALARM_PNG, ), - ) + ), ], ), body: EasyRefresh( diff --git a/lib/pages/message_center_page/message_center_page.dart b/lib/pages/message_center_page/message_center_page.dart index ed24e456..a2fb8d49 100644 --- a/lib/pages/message_center_page/message_center_page.dart +++ b/lib/pages/message_center_page/message_center_page.dart @@ -21,16 +21,11 @@ class MessageCenterPage extends StatefulWidget { } class _MessageCenterPageState extends State { - EasyRefreshController? _refreshController; - @override - void initState() { - super.initState(); - _refreshController = EasyRefreshController(); - } + EasyRefreshController _refreshController = EasyRefreshController(); @override void dispose() { - _refreshController?.dispose(); + _refreshController.dispose(); super.dispose(); } @@ -80,7 +75,7 @@ class _MessageCenterPageState extends State { MaterialButton( onPressed: () async { await NetUtil().dio!.get(API.message.allRead); - _refreshController!.callRefresh(); + _refreshController.callRefresh(); setState(() {}); }, child: '全部已读'.text.size(28.sp).black.make(), @@ -90,6 +85,7 @@ class _MessageCenterPageState extends State { body: EasyRefresh( header: MaterialHeader(), firstRefresh: true, + controller: _refreshController, onRefresh: () async { appProvider.getMessageCenter(); }, @@ -100,7 +96,12 @@ class _MessageCenterPageState extends State { title: '系统通知', content: appProvider.messageCenterModel.sysTitle ?? '无系统通知消息', count: appProvider.messageCenterModel.sysCount ?? 0, - onTap: () => Get.to(() => SystemMessagePage()), + onTap: () async { + await NetUtil().dio!.get(API.message.allReadComment); + await Get.to(() => SystemMessagePage()); + _refreshController.callRefresh(); + setState(() {}); + }, ), _buildCard( path: R.ASSETS_ICONS_COMMENT_NOTICE_PNG, @@ -110,7 +111,8 @@ class _MessageCenterPageState extends State { count: appProvider.messageCenterModel.commentCount ?? 0, onTap: () async { await NetUtil().dio!.get(API.message.allReadComment); - Get.to(() => CommentMessagePage()); + await Get.to(() => CommentMessagePage()); + _refreshController.callRefresh(); setState(() {}); }, ), diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index bfdaacb1..b6455839 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flustars/flustars.dart'; import 'package:get/get.dart'; +import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:provider/provider.dart'; import 'package:aku_community/constants/api.dart'; @@ -46,6 +47,7 @@ class UserProvider extends ChangeNotifier { Future updateProfile() async { _userInfoModel = await SignFunc.getUserInfo(); + await JPush().setAlias(_userInfoModel!.id.toString()); notifyListeners(); } diff --git a/lib/ui/community/community_views/community_page.dart b/lib/ui/community/community_views/community_page.dart index 54e20ebd..ef1dcb63 100644 --- a/lib/ui/community/community_views/community_page.dart +++ b/lib/ui/community/community_views/community_page.dart @@ -1,3 +1,5 @@ +import 'package:aku_community/provider/app_provider.dart'; +import 'package:badges/badges.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -53,16 +55,26 @@ class _CommunityPageState extends State Widget build(BuildContext context) { super.build(context); final userProvider = Provider.of(context); + final appProvider = Provider.of(context); return BeeScaffold( title: '社区', actions: [ - ColumnActionButton( - onPressed: () { - if (LoginUtil.isNotLogin) return; - Get.to(() => MessageCenterPage()); - }, - title: '消息', - path: R.ASSETS_ICONS_ALARM_PNG, + Badge( + elevation: 0, + showBadge: appProvider.messageCenterModel.commentCount != 0 || + appProvider.messageCenterModel.sysCount != 0, + position: BadgePosition.topEnd( + top: 8, + end: 8, + ), + child: ColumnActionButton( + onPressed: () { + if (LoginUtil.isNotLogin) return; + Get.to(() => MessageCenterPage()); + }, + title: '消息', + path: R.ASSETS_ICONS_ALARM_PNG, + ), ), ], fab: FloatingActionButton(