|
...
|
...
|
@@ -33,6 +33,7 @@ import 'package:permission_handler/permission_handler.dart'; |
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:tpns_flutter_plugin/tpns_flutter_plugin.dart';
|
|
|
|
import 'package:flutter_app_badger/flutter_app_badger.dart';
|
|
|
|
|
|
|
|
class HomePage extends StatefulWidget {
|
|
|
|
final int initialIndex; //初始tab
|
|
...
|
...
|
@@ -51,6 +52,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
|
|
int _currIndex = 1;
|
|
|
|
Color _activeColor = MyColours.color_199095;
|
|
|
|
Color _defaultColor = MyColours.color_999999;
|
|
|
|
int numPush = 0; //推送消息个数
|
|
|
|
|
|
|
|
Timer timer;
|
|
|
|
|
|
...
|
...
|
@@ -103,6 +105,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
|
|
|
|
|
|
//获取点击通知栏的自定义参数
|
|
|
|
_getIntent() async {
|
|
|
|
_clearBadge();
|
|
|
|
Map param = await Tools().getIntent();
|
|
|
|
Map notifyParam = param;
|
|
|
|
if (Platform.isIOS && param != null) {
|
|
...
|
...
|
@@ -152,7 +155,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
|
|
LogUtil.v("注册成功:$token");
|
|
|
|
// Utils.showToast("注册成功:$token");
|
|
|
|
userTokenInit(token);
|
|
|
|
XgFlutterPlugin().setAppBadge(0);
|
|
|
|
// XgFlutterPlugin().setAppBadge(0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unRegistered: (String msg) async {
|
|
...
|
...
|
@@ -160,6 +163,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
|
|
},
|
|
|
|
onReceiveNotificationResponse: (Map<String, dynamic> msg) async {
|
|
|
|
LogUtil.v("flutter onReceiveNotificationResponse $msg");
|
|
|
|
numPush++;
|
|
|
|
_addBadge();
|
|
|
|
},
|
|
|
|
onReceiveMessage: (Map<String, dynamic> msg) async {
|
|
|
|
print("flutter onReceiveMessage $msg");
|
|
...
|
...
|
@@ -167,8 +172,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
|
|
xgPushDidSetBadge: (String msg) async {
|
|
|
|
print("flutter xgPushDidSetBadge: $msg");
|
|
|
|
|
|
|
|
/// 在此可设置应用角标
|
|
|
|
XgFlutterPlugin().setAppBadge(0);
|
|
|
|
// /// 在此可设置应用角标
|
|
|
|
// XgFlutterPlugin().setAppBadge(0);
|
|
|
|
},
|
|
|
|
xgPushDidBindWithIdentifier: (String msg) async {
|
|
|
|
print("flutter xgPushDidBindWithIdentifier: $msg");
|
|
...
|
...
|
@@ -183,6 +188,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
|
|
print("flutter xgPushDidClearAllIdentifiers: $msg");
|
|
|
|
},
|
|
|
|
xgPushClickAction: (Map<String, dynamic> msg) async {
|
|
|
|
_clearBadge();
|
|
|
|
if (Platform.isIOS && msg != null && msg['custom'] != null) {
|
|
|
|
Map custom = json.decode(msg['custom'].toString());
|
|
|
|
switch (custom["messageType"].toString()) {
|
|
...
|
...
|
@@ -233,6 +239,19 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
|
|
xgCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _addBadge() {
|
|
|
|
XgFlutterPlugin().setBadge(numPush);
|
|
|
|
XgFlutterPlugin().setAppBadge(numPush);
|
|
|
|
FlutterAppBadger.updateBadgeCount(numPush);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _clearBadge() async {
|
|
|
|
numPush = 0;
|
|
|
|
XgFlutterPlugin().setBadge(0);
|
|
|
|
XgFlutterPlugin().setAppBadge(0);
|
|
|
|
FlutterAppBadger.removeBadge();
|
|
|
|
}
|
|
|
|
|
|
|
|
//初始化推送token
|
|
|
|
userTokenInit(String token) {
|
|
|
|
UserModel userModel = Provider.of<UserModel>(context, listen: false);
|
...
|
...
|
|