Explorar el Código

1.修改监听还原场景的顺序

tags/0.0.16+5
“yanghuaxuan” hace 3 años
padre
commit
160fce332f
Se han modificado 2 ficheros con 25 adiciones y 44 borrados
  1. +1
    -1
      example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java
  2. +24
    -43
      lib/pages/home_page/home_page.dart

+ 1
- 1
example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java Ver fichero

@@ -53,7 +53,7 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN
super.onCreate(savedInstanceState);
configureWindowForTransparency();
configureStatusBarForFullscreenFlutterExperience();
MobLink.setRestoreSceneListener(new MoblinkPlugin.SceneListener());
// MobLink.setRestoreSceneListener(new MoblinkPlugin.SceneListener());
addLaunchView();

}


+ 24
- 43
lib/pages/home_page/home_page.dart Ver fichero

@@ -54,8 +54,7 @@ class HomePage extends StatefulWidget {
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
class _HomePageState extends State<HomePage> with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
int _currentIndex = 0;
List<Map<String, dynamic>> _data = List();
static const EventChannel _eventChannel = const EventChannel('JAVA_TO_FLUTTER');
@@ -74,8 +73,7 @@ class _HomePageState extends State<HomePage>

//如果登出则重新打开首页
streamSubscription = EventUtil.instance.on<LogOut>().listen((event) async {
UserInfoModel user =
await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
user.token = '';
Navigator.maybePop(context);
print("重启1");
@@ -96,12 +94,17 @@ class _HomePageState extends State<HomePage>
try {
WidgetsBinding.instance.addObserver(this);

// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来)
eventChannelSubscription = _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);

///渲染完第一帧后调用
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
int delay = ((num.tryParse(AppConfigModel.appStartDelay) ?? 0.5) * 1000).toInt();
print("延时" + AppConfigModel.appStartDelay.toString());
Timer(Duration(milliseconds: delay), () {
NativeUtil.notifyInitSuccess();
//app后台杀死时候的还原
Moblink.restoreScene(_restore);
});
});

@@ -127,21 +130,13 @@ class _HomePageState extends State<HomePage>

}*/


// 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来)
eventChannelSubscription =
_eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);

//app后台杀死时候的还原
Moblink.restoreScene(_restore);
logOutSubscription = EventUtil.instance.on<LogOut>().listen((event) {
MobPushUtil.deleteAlias();
SharedPreferencesUtil.setStringValue(Constants.isSetTag, "0");
});

MobPushUtil.addPushReceiver();
loginSubscription =
EventUtil.instance.on<LoginSuccessEvent>().listen((event) async {
loginSubscription = EventUtil.instance.on<LoginSuccessEvent>().listen((event) async {
setAlias();
});
} catch (e, s) {
@@ -202,7 +197,7 @@ class _HomePageState extends State<HomePage>
List<Widget> contentWidgets = tabs.map((item) {
BaseTabModel model = BaseTabModel.fromJson(item);
//首页底部创建的item,把抖券判断置true
item['is_bottom_video']=true;
item['is_bottom_video'] = true;
return PageFactory.create(model.skipIdentifier, item);
}).toList();
if (_currentIndex >= contentWidgets.length) {
@@ -210,13 +205,12 @@ class _HomePageState extends State<HomePage>
}

return WillPopScope(
onWillPop: () async{
onWillPop: () async {
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HomepageBack>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
EventUtil.instance.fire("HomepageSignOut");
// 退出app
// await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
return true;

},
child: Scaffold(
body: IndexedStack(
@@ -252,9 +246,7 @@ class _HomePageState extends State<HomePage>
),
title: Text(
model.name,
style: TextStyle(
fontSize: 11,
color: HexColor.fromHex(_currentIndex == i ? chooseColor : textColor)),
style: TextStyle(fontSize: 11, color: HexColor.fromHex(_currentIndex == i ? chooseColor : textColor)),
)));
}
}
@@ -357,8 +349,7 @@ class _HomePageState extends State<HomePage>

Future<bool> _checkLimit(BaseTabModel model) async {
if (model.requiredLogin == '1') {
UserInfoModel user =
await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
print(user.toString());
if (user?.token == null || user.token == '') {
print('need login...');
@@ -379,20 +370,15 @@ class _HomePageState extends State<HomePage>
await Future.delayed(Duration(milliseconds: 1000), () async {
// 通知弹窗
///每打开5次检查一次权限
String showNotiPermissionTime = await SharedPreferencesUtil.getStringValue(
Constants.showNotiPermissionTime,
defaultVal: "5");
String showNotiPermissionTime = await SharedPreferencesUtil.getStringValue(Constants.showNotiPermissionTime, defaultVal: "5");
int timer = int.tryParse(showNotiPermissionTime) ?? 0;
if (timer % 5 == 0) {
timer++;
SharedPreferencesUtil.setStringValue(
Constants.showNotiPermissionTime, timer.toString());
SharedPreferencesUtil.setStringValue(Constants.showNotiPermissionTime, timer.toString());
if (!await Permission.storage.isGranted) {
await NotificationSettingDialogNew.show(context);
}
String notificationAgree = await SharedPreferencesUtil.getStringValue(
Constants.notificationAgree,
defaultVal: "0");
String notificationAgree = await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, defaultVal: "0");

if (notificationAgree == "1" && await Permission.notification.isGranted) {
///啥也不干
@@ -483,17 +469,14 @@ class _HomePageState extends State<HomePage>
void showAlert(String text, BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
title: new Text("提示"),
content: new Text(text),
actions: <Widget>[
new FlatButton(
child: new Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
)
]));
builder: (BuildContext context) => CupertinoAlertDialog(title: new Text("提示"), content: new Text(text), actions: <Widget>[
new FlatButton(
child: new Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
)
]));
}

@override
@@ -515,9 +498,7 @@ class _HomePageState extends State<HomePage>
///设置定向推送
void setAlias() async {
///如果没有开启通知则设置别名
if (await SharedPreferencesUtil.getStringValue(Constants.notificationAgree,
defaultVal: "0") ==
"1") {
if (await SharedPreferencesUtil.getStringValue(Constants.notificationAgree, defaultVal: "0") == "1") {
UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo;
var setting = await NativeUtil.getSetting();
String masterId = setting['master_id'];


Cargando…
Cancelar
Guardar