|
|
|
@ -24,6 +24,7 @@ import 'package:huixiang/utils/event_type.dart';
|
|
|
|
|
import 'package:huixiang/utils/flutter_utils.dart'; |
|
|
|
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
|
import 'package:huixiang/utils/native_event_handler.dart'; |
|
|
|
|
import 'package:huixiang/utils/push_event.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/update_dialog.dart'; |
|
|
|
|
import 'package:huixiang/vip/vip_page.dart'; |
|
|
|
|
import 'package:package_info_plus/package_info_plus.dart'; |
|
|
|
@ -120,6 +121,15 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
|
|
|
|
|
|
|
|
|
|
pushRoute(); |
|
|
|
|
|
|
|
|
|
eventBus.on<PushEvent>().listen((PushEvent event) { |
|
|
|
|
if (event.eventType == 0) { |
|
|
|
|
pushRoute(); |
|
|
|
|
} else if (event.eventType == 1) { |
|
|
|
|
MinePageState? state = minePageKey.currentState as MinePageState?; |
|
|
|
|
state?.queryMsgStats(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
String invite = ""; |
|
|
|
|
var interviewCouponList; |
|
|
|
|
var firstLoginCouponList; |
|
|
|
@ -191,8 +201,6 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
|
|
|
|
|
appAutoUpdate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final XgFlutterPlugin xgFlutterPlugin = XgFlutterPlugin(); |
|
|
|
|
|
|
|
|
|
// Future<void> initPlatformState() async { |
|
|
|
|
// String? platformVersion; |
|
|
|
|
// try { |
|
|
|
@ -214,71 +222,16 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
|
|
|
|
|
xgFlutterPlugin.setEnableDebug(true); |
|
|
|
|
|
|
|
|
|
///此处配置为iOS的appID信息,Android信息在build.gradle文件中 |
|
|
|
|
xgFlutterPlugin.startXg("1680005688", "IYIB3R2XRE22"); |
|
|
|
|
|
|
|
|
|
// xgFlutterPlugin.addEventHandler( |
|
|
|
|
// onReceiveMessage: (Map<String, dynamic> event) async { |
|
|
|
|
// print("onReceiveMessage: ${event.toString()}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// onReceiveNotificationResponse: (Map<String, dynamic> event) async { |
|
|
|
|
// print("onReceiveNotificationResponse: ${event.toString()}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// xgPushDidBindWithIdentifier: (Map<String, dynamic> event) async { |
|
|
|
|
// print("xgPushDidBindWithIdentifier: ${event.toString()}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// xgPushDidUnbindWithIdentifier: (Map<String, dynamic> event) async { |
|
|
|
|
// print("xgPushDidUnbindWithIdentifier: ${event.toString()}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// xgPushDidUpdatedBindedIdentifier: (Map<String, dynamic> event) async { |
|
|
|
|
// print("xgPushDidUpdatedBindedIdentifier: ${event.toString()}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// xgPushClickAction: (Map<String, dynamic> event) async { |
|
|
|
|
// print("xgPushClickAction: ${event.toString()}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// xgPushDidClearAllIdentifiers: (Map<String, dynamic> event) async { |
|
|
|
|
// print("xgPushDidClearAllIdentifiers: ${event.toString()}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// onRegisteredDeviceToken: (String res) async { |
|
|
|
|
// print("onRegisteredDeviceToken: ${res}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// onRegisteredDone: (String res) async { |
|
|
|
|
// print("onRegisteredDone: ${res}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// unRegistered: (String res) async { |
|
|
|
|
// print("unRegistered: ${res}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// xgPushNetworkConnected: (String res) async { |
|
|
|
|
// print("xgPushNetworkConnected: ${res}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// xgPushDidSetBadge: (String res) async { |
|
|
|
|
// print("xgPushDidSetBadge: ${res}"); |
|
|
|
|
// return true; |
|
|
|
|
// }, |
|
|
|
|
// ); |
|
|
|
|
// xgFlutterPlugin.startXg("1680005688", "IYIB3R2XRE22"); |
|
|
|
|
xgFlutterPlugin.startXg("1580005689", "A1HKKUUWI7WI"); |
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) { |
|
|
|
|
XgAndroidApi androidApi = xgFlutterPlugin.getXgAndroidApi(); |
|
|
|
|
//小米 |
|
|
|
|
androidApi.setMiPushAppId(appId: "2882303761520050452"); |
|
|
|
|
androidApi.setMiPushAppKey(appKey: "5582005091452"); |
|
|
|
|
|
|
|
|
|
androidApi.enableOtherPush(); |
|
|
|
|
androidApi.regPush(); |
|
|
|
|
XgFlutterPlugin.xgApi.setMiPushAppId(appId: "2882303761520050452"); |
|
|
|
|
XgFlutterPlugin.xgApi.setMiPushAppKey(appKey: "5582005091452"); |
|
|
|
|
XgFlutterPlugin.xgApi.enableOtherPush(); |
|
|
|
|
XgFlutterPlugin.xgApi.regPush(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ===========================TPNS==== |
|
|
|
|
|
|
|
|
|
ShareSDKRegister shareSDKRegister = ShareSDKRegister(); |
|
|
|
|
shareSDKRegister.setupWechat( |
|
|
|
|
"wx3b269e795ed23e5f", |
|
|
|
@ -306,78 +259,76 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
|
|
|
|
|
BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) { |
|
|
|
|
xgFlutterPlugin.getXgAndroidApi().addNativeEventHandler( |
|
|
|
|
MyNativeEventHandler( |
|
|
|
|
(String title, String message, String customContent, int type) { |
|
|
|
|
print("xgPushClickAction2: $customContent"); |
|
|
|
|
SharedPreferences.getInstance().then((value) { |
|
|
|
|
value.setString("pushData", customContent); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// @typed: ARTICLE(1)文章 ACTIVITY(2)活动 SHOP(3)店铺 CREDIT_GOODS(4)积分商品 ORDER(5)订单 TREND(6)动态 MEMBER(7)用户 WALLET(8)平台余额/钱包 WELFARE(9)福利中心 COUPON(12)优惠券列表 CATE_BEAN(13)我的印章 |
|
|
|
|
xgFlutterPlugin.addEventHandler(xgPushClickAction: (event) async { |
|
|
|
|
print("xgPushClickAction1: $event"); |
|
|
|
|
if (event["actionType"] == 2) return event; |
|
|
|
|
if (Platform.isAndroid |
|
|
|
|
? (event["actionType"] == 0) |
|
|
|
|
: (event["xg"]["msgtype"] == 1) && |
|
|
|
|
event[Platform.isAndroid ? "customMessage" : "custom"] != null) { |
|
|
|
|
SharedPreferences.getInstance().then((value) { |
|
|
|
|
value.setString("pushData", |
|
|
|
|
event[Platform.isAndroid ? "customMessage" : "custom"]); |
|
|
|
|
}); |
|
|
|
|
if ((ModalRoute.of(context)?.isActive ?? false) |
|
|
|
|
&& (ModalRoute.of(context)?.isCurrent ?? false)) { |
|
|
|
|
pushRoute(); |
|
|
|
|
} else { |
|
|
|
|
Navigator.of(context) |
|
|
|
|
.pushNamedAndRemoveUntil('/router/main_page', (route) => false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return event; |
|
|
|
|
}, onReceiveNotificationResponse: (event) async { |
|
|
|
|
try { |
|
|
|
|
if (jsonDecode(event["customMessage"])["typed"] == 6) { |
|
|
|
|
// HomePageState state = homePageKey.currentState; |
|
|
|
|
// state.queryMsgStats(); |
|
|
|
|
MinePageState state = minePageKey.currentState as MinePageState; |
|
|
|
|
state.queryMsgStats(); |
|
|
|
|
} |
|
|
|
|
} catch (ex) {} |
|
|
|
|
print("onReceiveNotificationResponse: ${event.toString()}"); |
|
|
|
|
return event; |
|
|
|
|
}, onReceiveMessage: (event) async { |
|
|
|
|
print("onReceiveMessage: ${event.toString()}"); |
|
|
|
|
return event; |
|
|
|
|
}, onRegisteredDone: (event) async { |
|
|
|
|
print("onRegisteredDone: ${event.toString()}"); |
|
|
|
|
return event; |
|
|
|
|
}, xgPushDidBindWithIdentifier: (event) async { |
|
|
|
|
print("xgPushDidBindWithIdentifier: ${event.toString()}"); |
|
|
|
|
return event; |
|
|
|
|
}); |
|
|
|
|
// if (Platform.isAndroid) { |
|
|
|
|
// xgFlutterPlugin.getXgAndroidApi().addNativeEventHandler( |
|
|
|
|
// MyNativeEventHandler( |
|
|
|
|
// (String title, String message, String customContent, int type) { |
|
|
|
|
// print("xgPushClickAction2: $customContent"); |
|
|
|
|
// SharedPreferences.getInstance().then((value) { |
|
|
|
|
// value.setString("pushData", customContent); |
|
|
|
|
// }); |
|
|
|
|
// }, |
|
|
|
|
// ), |
|
|
|
|
// ); |
|
|
|
|
// } |
|
|
|
|
/// @typed: ARTICLE(1)文章 ACTIVITY(2)活动 SHOP(3)店铺 |
|
|
|
|
/// CREDIT_GOODS(4)积分商品 ORDER(5)订单 TREND(6)动态 MEMBER(7)用户 |
|
|
|
|
/// WALLET(8)平台余额/钱包 WELFARE(9)福利中心 COUPON(12)优惠券列表 |
|
|
|
|
/// CATE_BEAN(13)我的印章 |
|
|
|
|
// xgFlutterPlugin.addEventHandler(xgPushClickAction: (event) async { |
|
|
|
|
// print("xgPushClickAction1: $event"); |
|
|
|
|
// if (event["actionType"] == 2) return event; |
|
|
|
|
// if (Platform.isAndroid |
|
|
|
|
// ? (event["actionType"] == 0) |
|
|
|
|
// : (event["xg"]?["msgtype"] == 1) && |
|
|
|
|
// event[Platform.isAndroid ? "customMessage" : "custom"] != null) { |
|
|
|
|
// SharedPreferences.getInstance().then((value) { |
|
|
|
|
// value.setString("pushData", |
|
|
|
|
// event[Platform.isAndroid ? "customMessage" : "custom"]); |
|
|
|
|
// }); |
|
|
|
|
// if ((ModalRoute.of(context)?.isActive ?? false) |
|
|
|
|
// && (ModalRoute.of(context)?.isCurrent ?? false)) { |
|
|
|
|
// pushRoute(); |
|
|
|
|
// } else { |
|
|
|
|
// Navigator.of(context).pushNamedAndRemoveUntil( |
|
|
|
|
// '/router/main_page', |
|
|
|
|
// (route) => false, |
|
|
|
|
// ); |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// return event; |
|
|
|
|
// }, onReceiveNotificationResponse: (event) async { |
|
|
|
|
// try { |
|
|
|
|
// if (jsonDecode(event["customMessage"])["typed"] == 6) { |
|
|
|
|
// // HomePageState state = homePageKey.currentState; |
|
|
|
|
// // state.queryMsgStats(); |
|
|
|
|
// MinePageState state = minePageKey.currentState as MinePageState; |
|
|
|
|
// state.queryMsgStats(); |
|
|
|
|
// } |
|
|
|
|
// } catch (ex) {} |
|
|
|
|
// print("onReceiveNotificationResponse: ${event.toString()}"); |
|
|
|
|
// return event; |
|
|
|
|
// }, onReceiveMessage: (event) async { |
|
|
|
|
// print("onReceiveMessage: ${event.toString()}"); |
|
|
|
|
// return event; |
|
|
|
|
// }, onRegisteredDone: (event) async { |
|
|
|
|
// print("onRegisteredDone: ${event.toString()}"); |
|
|
|
|
// return event; |
|
|
|
|
// }, xgPushDidBindWithIdentifier: (event) async { |
|
|
|
|
// print("xgPushDidBindWithIdentifier: ${event.toString()}"); |
|
|
|
|
// return event; |
|
|
|
|
// }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pushRoute() async { |
|
|
|
|
SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); |
|
|
|
|
if (sharedPreferences.getString("token") == null || |
|
|
|
|
sharedPreferences.getString("token") == "") return; |
|
|
|
|
String? startIntent; |
|
|
|
|
// if (Platform.isAndroid) startIntent = await Bridge.getStartIntent(); |
|
|
|
|
print("intent:${startIntent}"); |
|
|
|
|
String pushData = ""; |
|
|
|
|
if (startIntent != null && startIntent != "") { |
|
|
|
|
pushData = startIntent; |
|
|
|
|
// pushData = """{"typed":1,"info":"1420304936817655808"}"""; |
|
|
|
|
} else { |
|
|
|
|
pushData = sharedPreferences.getString("pushData") ?? ""; |
|
|
|
|
} |
|
|
|
|
if (pushData == "") return; |
|
|
|
|
String pushData = sharedPreferences.getString("pushData") ?? ""; |
|
|
|
|
print("intent:${pushData}"); |
|
|
|
|
|
|
|
|
|
if (pushData.isEmpty) return; |
|
|
|
|
Map<String, dynamic> pushMap = jsonDecode(pushData); |
|
|
|
|
String routeName = ""; |
|
|
|
|
Map<String, dynamic> params = {}; |
|
|
|
@ -437,10 +388,10 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
|
|
|
|
|
} |
|
|
|
|
sharedPreferences.setString("pushData", ""); |
|
|
|
|
print("xgPushClickAction: routeName: $routeName"); |
|
|
|
|
if (routeName != "") { |
|
|
|
|
if (routeName.isNotEmpty) { |
|
|
|
|
Navigator.of(context).pushNamed(routeName, arguments: params); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
queryUserInfo() async { |
|
|
|
|
SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); |
|
|
|
@ -450,7 +401,9 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
|
|
|
|
|
Dio(), |
|
|
|
|
context: context, |
|
|
|
|
token: sharedPreferences.getString('token') ?? "", |
|
|
|
|
).queryInfo().catchError((onError) {}); |
|
|
|
|
).queryInfo().catchError((error) { |
|
|
|
|
print("error: ${error}"); |
|
|
|
|
}); |
|
|
|
|
sharedPreferences.setString('user', jsonEncode(baseDate.data)); |
|
|
|
|
|
|
|
|
|
//用户登录时,注册推送的标识是手机号 |
|
|
|
|