更新消息通知

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

@ -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<AppProvider>(Get.context!, listen: false);
appProvider.getMessageCenter();
},
onOpenNotification: jPushLogger('onOpenNotification'),
onReceiveMessage: jPushLogger('onReceiveMessage'),

@ -69,8 +69,12 @@ class _HomePageState extends State<HomePage>
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<HomePage>
title: '消息',
path: R.ASSETS_ICONS_ALARM_PNG,
),
)
),
],
),
body: EasyRefresh(

@ -21,16 +21,11 @@ class MessageCenterPage extends StatefulWidget {
}
class _MessageCenterPageState extends State<MessageCenterPage> {
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<MessageCenterPage> {
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<MessageCenterPage> {
body: EasyRefresh(
header: MaterialHeader(),
firstRefresh: true,
controller: _refreshController,
onRefresh: () async {
appProvider.getMessageCenter();
},
@ -100,7 +96,12 @@ class _MessageCenterPageState extends State<MessageCenterPage> {
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<MessageCenterPage> {
count: appProvider.messageCenterModel.commentCount ?? 0,
onTap: () async {
await NetUtil().dio!.get(API.message.allReadComment);
Get.to(() => CommentMessagePage());
await Get.to(() => CommentMessagePage());
_refreshController.callRefresh();
setState(() {});
},
),

@ -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();
}

@ -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<CommunityPage>
Widget build(BuildContext context) {
super.build(context);
final userProvider = Provider.of<UserProvider>(context);
final appProvider = Provider.of<AppProvider>(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(

Loading…
Cancel
Save