fmk
3 years ago
7 changed files with 203 additions and 70 deletions
@ -0,0 +1,84 @@
|
||||
|
||||
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(); |
||||
WidgetsBinding.instance.removeObserver(this); |
||||
} |
||||
|
||||
@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(); |
||||
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"]) { |
||||
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); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue