|
@@ -33,6 +33,7 @@ import 'package:permission_handler/permission_handler.dart'; |
|
@@ -33,6 +33,7 @@ import 'package:permission_handler/permission_handler.dart'; |
|
33
|
import 'package:provider/provider.dart';
|
33
|
import 'package:provider/provider.dart';
|
|
34
|
import 'package:shared_preferences/shared_preferences.dart';
|
34
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
35
|
import 'package:tpns_flutter_plugin/tpns_flutter_plugin.dart';
|
35
|
import 'package:tpns_flutter_plugin/tpns_flutter_plugin.dart';
|
|
|
|
36
|
+import 'package:flutter_app_badger/flutter_app_badger.dart';
|
|
36
|
|
37
|
|
|
37
|
class HomePage extends StatefulWidget {
|
38
|
class HomePage extends StatefulWidget {
|
|
38
|
final int initialIndex; //初始tab
|
39
|
final int initialIndex; //初始tab
|
|
@@ -51,6 +52,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
@@ -51,6 +52,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
51
|
int _currIndex = 1;
|
52
|
int _currIndex = 1;
|
|
52
|
Color _activeColor = MyColours.color_199095;
|
53
|
Color _activeColor = MyColours.color_199095;
|
|
53
|
Color _defaultColor = MyColours.color_999999;
|
54
|
Color _defaultColor = MyColours.color_999999;
|
|
|
|
55
|
+ int numPush = 0; //推送消息个数
|
|
54
|
|
56
|
|
|
55
|
Timer timer;
|
57
|
Timer timer;
|
|
56
|
|
58
|
|
|
@@ -103,6 +105,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
@@ -103,6 +105,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
103
|
|
105
|
|
|
104
|
//获取点击通知栏的自定义参数
|
106
|
//获取点击通知栏的自定义参数
|
|
105
|
_getIntent() async {
|
107
|
_getIntent() async {
|
|
|
|
108
|
+ _clearBadge();
|
|
106
|
Map param = await Tools().getIntent();
|
109
|
Map param = await Tools().getIntent();
|
|
107
|
Map notifyParam = param;
|
110
|
Map notifyParam = param;
|
|
108
|
if (Platform.isIOS && param != null) {
|
111
|
if (Platform.isIOS && param != null) {
|
|
@@ -152,7 +155,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
@@ -152,7 +155,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
152
|
LogUtil.v("注册成功:$token");
|
155
|
LogUtil.v("注册成功:$token");
|
|
153
|
// Utils.showToast("注册成功:$token");
|
156
|
// Utils.showToast("注册成功:$token");
|
|
154
|
userTokenInit(token);
|
157
|
userTokenInit(token);
|
|
155
|
- XgFlutterPlugin().setAppBadge(0);
|
158
|
+ // XgFlutterPlugin().setAppBadge(0);
|
|
156
|
}
|
159
|
}
|
|
157
|
},
|
160
|
},
|
|
158
|
unRegistered: (String msg) async {
|
161
|
unRegistered: (String msg) async {
|
|
@@ -160,6 +163,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
@@ -160,6 +163,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
160
|
},
|
163
|
},
|
|
161
|
onReceiveNotificationResponse: (Map<String, dynamic> msg) async {
|
164
|
onReceiveNotificationResponse: (Map<String, dynamic> msg) async {
|
|
162
|
LogUtil.v("flutter onReceiveNotificationResponse $msg");
|
165
|
LogUtil.v("flutter onReceiveNotificationResponse $msg");
|
|
|
|
166
|
+ numPush++;
|
|
|
|
167
|
+ _addBadge();
|
|
163
|
},
|
168
|
},
|
|
164
|
onReceiveMessage: (Map<String, dynamic> msg) async {
|
169
|
onReceiveMessage: (Map<String, dynamic> msg) async {
|
|
165
|
print("flutter onReceiveMessage $msg");
|
170
|
print("flutter onReceiveMessage $msg");
|
|
@@ -167,8 +172,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
@@ -167,8 +172,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
167
|
xgPushDidSetBadge: (String msg) async {
|
172
|
xgPushDidSetBadge: (String msg) async {
|
|
168
|
print("flutter xgPushDidSetBadge: $msg");
|
173
|
print("flutter xgPushDidSetBadge: $msg");
|
|
169
|
|
174
|
|
|
170
|
- /// 在此可设置应用角标
|
|
|
|
171
|
- XgFlutterPlugin().setAppBadge(0);
|
175
|
+ // /// 在此可设置应用角标
|
|
|
|
176
|
+ // XgFlutterPlugin().setAppBadge(0);
|
|
172
|
},
|
177
|
},
|
|
173
|
xgPushDidBindWithIdentifier: (String msg) async {
|
178
|
xgPushDidBindWithIdentifier: (String msg) async {
|
|
174
|
print("flutter xgPushDidBindWithIdentifier: $msg");
|
179
|
print("flutter xgPushDidBindWithIdentifier: $msg");
|
|
@@ -183,6 +188,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
@@ -183,6 +188,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
183
|
print("flutter xgPushDidClearAllIdentifiers: $msg");
|
188
|
print("flutter xgPushDidClearAllIdentifiers: $msg");
|
|
184
|
},
|
189
|
},
|
|
185
|
xgPushClickAction: (Map<String, dynamic> msg) async {
|
190
|
xgPushClickAction: (Map<String, dynamic> msg) async {
|
|
|
|
191
|
+ _clearBadge();
|
|
186
|
if (Platform.isIOS && msg != null && msg['custom'] != null) {
|
192
|
if (Platform.isIOS && msg != null && msg['custom'] != null) {
|
|
187
|
Map custom = json.decode(msg['custom'].toString());
|
193
|
Map custom = json.decode(msg['custom'].toString());
|
|
188
|
switch (custom["messageType"].toString()) {
|
194
|
switch (custom["messageType"].toString()) {
|
|
@@ -233,6 +239,19 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
@@ -233,6 +239,19 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver { |
|
233
|
xgCount++;
|
239
|
xgCount++;
|
|
234
|
}
|
240
|
}
|
|
235
|
|
241
|
|
|
|
|
242
|
+ void _addBadge() {
|
|
|
|
243
|
+ XgFlutterPlugin().setBadge(numPush);
|
|
|
|
244
|
+ XgFlutterPlugin().setAppBadge(numPush);
|
|
|
|
245
|
+ FlutterAppBadger.updateBadgeCount(numPush);
|
|
|
|
246
|
+ }
|
|
|
|
247
|
+
|
|
|
|
248
|
+ void _clearBadge() async {
|
|
|
|
249
|
+ numPush = 0;
|
|
|
|
250
|
+ XgFlutterPlugin().setBadge(0);
|
|
|
|
251
|
+ XgFlutterPlugin().setAppBadge(0);
|
|
|
|
252
|
+ FlutterAppBadger.removeBadge();
|
|
|
|
253
|
+ }
|
|
|
|
254
|
+
|
|
236
|
//初始化推送token
|
255
|
//初始化推送token
|
|
237
|
userTokenInit(String token) {
|
256
|
userTokenInit(String token) {
|
|
238
|
UserModel userModel = Provider.of<UserModel>(context, listen: false);
|
257
|
UserModel userModel = Provider.of<UserModel>(context, listen: false);
|