You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

118 lines
3.7 KiB

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:huixiang/utils/bridge.dart';
import 'package:shared_preferences/shared_preferences.dart';
abstract class BaseState<T extends StatefulWidget> extends State<T>
with WidgetsBindingObserver {
int lastTime = DateTime.now().millisecondsSinceEpoch;
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print("-didChangeAppLifecycleState-" + state.toString());
switch (state) {
case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。
break;
case AppLifecycleState.resumed: //从后台切换前台,界面可见
pushRoute();
if (DateTime.now().millisecondsSinceEpoch - lastTime > 300000)
Navigator.of(context).popAndPushNamed('/router/main_page');
break;
case AppLifecycleState.paused: // 界面不可见,后台
lastTime = DateTime.now().millisecondsSinceEpoch;
break;
case AppLifecycleState.detached: // APP结束时调用
break;
}
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
pushRoute() async {
String startIntent = await Bridge.getStartIntent();
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
print("intent:$startIntent");
String pushData = "";
if (startIntent != null && startIntent != "") {
pushData = startIntent;
} else {
pushData = sharedPreferences.getString("pushData");
}
if (pushData == null || pushData == "") return;
Map<String, dynamic> pushMap = jsonDecode(pushData);
if (pushMap != null) {
String routeName = "";
Map<String, dynamic> params = {};
switch (pushMap["typed"].toString()) {
case "1":
case "ARTICLE":
routeName = "/router/web_page";
params["articleId"] = pushMap["info"];
break;
case "2":
case "ACTIVITY":
routeName = "/router/web_page";
params["activityId"] = pushMap["info"];
break;
case "3":
case "SHOP":
routeName = "/router/store_order";
params["id"] = pushMap["info"];
params["tenant"] = pushMap["tenant"];
params["storeName"] = pushMap["storeName"];
break;
case "4":
case "CREDIT_GOODS":
routeName = "/router/integral_store_page";
params["goodsId"] = pushMap["info"];
break;
case "5":
case "ORDER":
routeName = "/router/order_details";
params["id"] = pushMap["info"];
break;
case "6":
case "MEMBER":
routeName = "/router/community_details";
params["businessId"] = pushMap["info"];
break;
case "8":
case "WALLET":
routeName = "/router/mine_wallet";
params["id"] = pushMap["info"];
break;
case "9":
case "WELFARE":
routeName = "/router/welfare_page";
params["id"] = pushMap["info"];
break;
case "12":
case "COUPON":
routeName = "/router/coupon_page";
params["id"] = pushMap["info"];
break;
case "13":
case "CATE_BEAN":
routeName = "/router/trading_card_page";
params["id"] = pushMap["info"];
break;
}
sharedPreferences.setString("pushData", "");
print("xgPushClickAction: routeName: $routeName");
if (routeName != "") {
Navigator.of(context).pushNamed(routeName, arguments: params);
}
}
}
}