更新消息通知

hmxc
小赖 4 years ago
parent 8aba2b4650
commit 0ed31f49fd

@ -1,5 +1,6 @@
import 'dart:io'; import 'dart:io';
import 'package:aku_community/provider/app_provider.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.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_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
import 'package:get/get.dart';
import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
import 'package:aku_community/constants/app_theme.dart'; import 'package:aku_community/constants/app_theme.dart';
import 'package:aku_community/constants/config.dart'; import 'package:aku_community/constants/config.dart';
import 'package:aku_community/utils/message_parser.dart'; import 'package:aku_community/utils/message_parser.dart';
import 'package:provider/provider.dart';
class MainInitialize { class MainInitialize {
///firebase ///firebase
@ -52,6 +55,9 @@ class MainInitialize {
onReceiveNotification: (message) async { onReceiveNotification: (message) async {
LoggerData.addData(message, tag: 'onReceiveNotification'); LoggerData.addData(message, tag: 'onReceiveNotification');
await MessageParser(message).shot(); await MessageParser(message).shot();
final appProvider =
Provider.of<AppProvider>(Get.context!, listen: false);
appProvider.getMessageCenter();
}, },
onOpenNotification: jPushLogger('onOpenNotification'), onOpenNotification: jPushLogger('onOpenNotification'),
onReceiveMessage: jPushLogger('onReceiveMessage'), onReceiveMessage: jPushLogger('onReceiveMessage'),

@ -69,8 +69,12 @@ class _HomePageState extends State<HomePage>
actions: [ actions: [
Badge( Badge(
elevation: 0, elevation: 0,
showBadge: appProvider.messageCenterModel.sysCount == 0, showBadge: appProvider.messageCenterModel.commentCount != 0 ||
position: BadgePosition.topEnd(), appProvider.messageCenterModel.sysCount != 0,
position: BadgePosition.topEnd(
top: 8,
end: 8,
),
child: ColumnActionButton( child: ColumnActionButton(
onPressed: () { onPressed: () {
if (LoginUtil.isNotLogin) return; if (LoginUtil.isNotLogin) return;
@ -79,7 +83,7 @@ class _HomePageState extends State<HomePage>
title: '消息', title: '消息',
path: R.ASSETS_ICONS_ALARM_PNG, path: R.ASSETS_ICONS_ALARM_PNG,
), ),
) ),
], ],
), ),
body: EasyRefresh( body: EasyRefresh(

@ -21,16 +21,11 @@ class MessageCenterPage extends StatefulWidget {
} }
class _MessageCenterPageState extends State<MessageCenterPage> { class _MessageCenterPageState extends State<MessageCenterPage> {
EasyRefreshController? _refreshController; EasyRefreshController _refreshController = EasyRefreshController();
@override
void initState() {
super.initState();
_refreshController = EasyRefreshController();
}
@override @override
void dispose() { void dispose() {
_refreshController?.dispose(); _refreshController.dispose();
super.dispose(); super.dispose();
} }
@ -80,7 +75,7 @@ class _MessageCenterPageState extends State<MessageCenterPage> {
MaterialButton( MaterialButton(
onPressed: () async { onPressed: () async {
await NetUtil().dio!.get(API.message.allRead); await NetUtil().dio!.get(API.message.allRead);
_refreshController!.callRefresh(); _refreshController.callRefresh();
setState(() {}); setState(() {});
}, },
child: '全部已读'.text.size(28.sp).black.make(), child: '全部已读'.text.size(28.sp).black.make(),
@ -90,6 +85,7 @@ class _MessageCenterPageState extends State<MessageCenterPage> {
body: EasyRefresh( body: EasyRefresh(
header: MaterialHeader(), header: MaterialHeader(),
firstRefresh: true, firstRefresh: true,
controller: _refreshController,
onRefresh: () async { onRefresh: () async {
appProvider.getMessageCenter(); appProvider.getMessageCenter();
}, },
@ -100,7 +96,12 @@ class _MessageCenterPageState extends State<MessageCenterPage> {
title: '系统通知', title: '系统通知',
content: appProvider.messageCenterModel.sysTitle ?? '无系统通知消息', content: appProvider.messageCenterModel.sysTitle ?? '无系统通知消息',
count: appProvider.messageCenterModel.sysCount ?? 0, 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( _buildCard(
path: R.ASSETS_ICONS_COMMENT_NOTICE_PNG, path: R.ASSETS_ICONS_COMMENT_NOTICE_PNG,
@ -110,7 +111,8 @@ class _MessageCenterPageState extends State<MessageCenterPage> {
count: appProvider.messageCenterModel.commentCount ?? 0, count: appProvider.messageCenterModel.commentCount ?? 0,
onTap: () async { onTap: () async {
await NetUtil().dio!.get(API.message.allReadComment); await NetUtil().dio!.get(API.message.allReadComment);
Get.to(() => CommentMessagePage()); await Get.to(() => CommentMessagePage());
_refreshController.callRefresh();
setState(() {}); setState(() {});
}, },
), ),

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flustars/flustars.dart'; import 'package:flustars/flustars.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:aku_community/constants/api.dart'; import 'package:aku_community/constants/api.dart';
@ -46,6 +47,7 @@ class UserProvider extends ChangeNotifier {
Future updateProfile() async { Future updateProfile() async {
_userInfoModel = await SignFunc.getUserInfo(); _userInfoModel = await SignFunc.getUserInfo();
await JPush().setAlias(_userInfoModel!.id.toString());
notifyListeners(); notifyListeners();
} }

@ -1,3 +1,5 @@
import 'package:aku_community/provider/app_provider.dart';
import 'package:badges/badges.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@ -53,10 +55,19 @@ class _CommunityPageState extends State<CommunityPage>
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); super.build(context);
final userProvider = Provider.of<UserProvider>(context); final userProvider = Provider.of<UserProvider>(context);
final appProvider = Provider.of<AppProvider>(context);
return BeeScaffold( return BeeScaffold(
title: '社区', title: '社区',
actions: [ actions: [
ColumnActionButton( Badge(
elevation: 0,
showBadge: appProvider.messageCenterModel.commentCount != 0 ||
appProvider.messageCenterModel.sysCount != 0,
position: BadgePosition.topEnd(
top: 8,
end: 8,
),
child: ColumnActionButton(
onPressed: () { onPressed: () {
if (LoginUtil.isNotLogin) return; if (LoginUtil.isNotLogin) return;
Get.to(() => MessageCenterPage()); Get.to(() => MessageCenterPage());
@ -64,6 +75,7 @@ class _CommunityPageState extends State<CommunityPage>
title: '消息', title: '消息',
path: R.ASSETS_ICONS_ALARM_PNG, path: R.ASSETS_ICONS_ALARM_PNG,
), ),
),
], ],
fab: FloatingActionButton( fab: FloatingActionButton(
onPressed: () async { onPressed: () async {

Loading…
Cancel
Save