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.

84 lines
2.5 KiB

3 years ago
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 {
@override
void dispose() {
super.dispose();
3 years ago
WidgetsBinding.instance!.removeObserver(this);
3 years ago
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print("-didChangeAppLifecycleState-" + state.toString());
switch (state) {
case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。
break;
case AppLifecycleState.resumed: //从后台切换前台,界面可见
pushRoute();
break;
case AppLifecycleState.paused: // 界面不可见,后台
break;
case AppLifecycleState.detached: // APP结束时调用
break;
}
}
@override
void initState() {
super.initState();
3 years ago
WidgetsBinding.instance!.addObserver(this);
3 years ago
}
pushRoute() async {
String startIntent = await Bridge.getStartIntent();
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
print("intent:$startIntent");
3 years ago
String? pushData = "";
3 years ago
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"]) {
case 1:
routeName = "/router/store_detail_page";
params["articleId"] = pushMap["info"];
break;
case 2:
routeName = "/router/store_detail_page";
params["activityId"] = pushMap["info"];
break;
case 3:
routeName = "/router/union_detail_page";
params["id"] = pushMap["info"];
break;
case 4:
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");
if (routeName != "") {
Navigator.of(context).pushNamed(routeName, arguments: params);
}
}
}
}