|
|
|
@ -12,6 +12,7 @@ import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
|
import 'package:huixiang/union/union_page.dart'; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
import 'package:huixiang/utils/event_type.dart'; |
|
|
|
|
import 'package:huixiang/utils/native_event_handler.dart'; |
|
|
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
|
|
|
|
|
@ -23,7 +24,6 @@ class MainPage extends StatefulWidget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class _MainPage extends State<MainPage> { |
|
|
|
|
|
|
|
|
|
List<Widget> _widgetOptions; |
|
|
|
|
|
|
|
|
|
List<String> icons; |
|
|
|
@ -63,14 +63,38 @@ class _MainPage extends State<MainPage> {
|
|
|
|
|
|
|
|
|
|
queryUserInfo(); |
|
|
|
|
|
|
|
|
|
/// @typed: 1文章 2活动 3店铺 4积分商品 |
|
|
|
|
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: 1文章 2活动 3店铺 4积分商品 5订单 |
|
|
|
|
xgFlutterPlugin.addEventHandler(xgPushClickAction: (event) async { |
|
|
|
|
print("xgPushClickAction1: ${event.toString()}"); |
|
|
|
|
print("xgPushClickAction1: $event"); |
|
|
|
|
if (event["actionType"] == 2) return event; |
|
|
|
|
if (event["actionType"] == 0 && event["customMessage"] != null) { |
|
|
|
|
if (Platform.isAndroid |
|
|
|
|
? (event["actionType"] == 0) |
|
|
|
|
: (event["xg"]["msgtype"] == 1) && |
|
|
|
|
event[Platform.isAndroid ? "customMessage" : "custom"] != null) { |
|
|
|
|
SharedPreferences.getInstance().then((value) { |
|
|
|
|
value.setString("pushData", event["customMessage"]); |
|
|
|
|
value.setString("pushData", |
|
|
|
|
event[Platform.isAndroid ? "customMessage" : "custom"]); |
|
|
|
|
}); |
|
|
|
|
print("ModalRoute isActive: ${ModalRoute.of(context).isActive}"); |
|
|
|
|
print("ModalRoute isCurrent: ${ModalRoute.of(context).isCurrent}"); |
|
|
|
|
print("ModalRoute isFirst: ${ModalRoute.of(context).isFirst}"); |
|
|
|
|
if (ModalRoute.of(context).isActive && |
|
|
|
|
ModalRoute.of(context).isCurrent) { |
|
|
|
|
pushRoute(); |
|
|
|
|
} else { |
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil('/router/main_page', (route) => false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return event; |
|
|
|
|
}, onReceiveNotificationResponse: (event) async { |
|
|
|
@ -80,7 +104,6 @@ class _MainPage extends State<MainPage> {
|
|
|
|
|
print("onReceiveMessage: ${event.toString()}"); |
|
|
|
|
return event; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pushRoute() async { |
|
|
|
@ -108,6 +131,10 @@ class _MainPage extends State<MainPage> {
|
|
|
|
|
routeName = "/router/integral_store_page"; |
|
|
|
|
params["goodsId"] = pushMap["info"]; |
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
routeName = "/router/order_details"; |
|
|
|
|
params["id"] = pushMap["info"]; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
sharedPreferences.setString("pushData", ""); |
|
|
|
|
print("xgPushClickAction: routeName: $routeName"); |
|
|
|
@ -119,7 +146,8 @@ class _MainPage extends State<MainPage> {
|
|
|
|
|
|
|
|
|
|
queryUserInfo() async { |
|
|
|
|
SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); |
|
|
|
|
if (sharedPreferences.getString("token") == null || sharedPreferences.getString("token") == "") return; |
|
|
|
|
if (sharedPreferences.getString("token") == null || |
|
|
|
|
sharedPreferences.getString("token") == "") return; |
|
|
|
|
BaseData baseDate = await ApiService(Dio(), |
|
|
|
|
context: context, token: sharedPreferences.getString('token')) |
|
|
|
|
.queryInfo(); |
|
|
|
|