diff --git a/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java b/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java index 65232b5..6f2cd4f 100644 --- a/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java +++ b/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java @@ -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(); } diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index 76b3521..07536ef 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -54,8 +54,7 @@ class HomePage extends StatefulWidget { _HomePageState createState() => _HomePageState(); } -class _HomePageState extends State - with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin { +class _HomePageState extends State with WidgetsBindingObserver, TickerProviderStateMixin, AutomaticKeepAliveClientMixin { int _currentIndex = 0; List> _data = List(); static const EventChannel _eventChannel = const EventChannel('JAVA_TO_FLUTTER'); @@ -74,8 +73,7 @@ class _HomePageState extends State //如果登出则重新打开首页 streamSubscription = EventUtil.instance.on().listen((event) async { - UserInfoModel user = - await Provider.of(context, listen: false).getUserInfoModel(); + UserInfoModel user = await Provider.of(context, listen: false).getUserInfoModel(); user.token = ''; Navigator.maybePop(context); print("重启1"); @@ -96,12 +94,17 @@ class _HomePageState extends State 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 }*/ - - // 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来) - eventChannelSubscription = - _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); - - //app后台杀死时候的还原 - Moblink.restoreScene(_restore); logOutSubscription = EventUtil.instance.on().listen((event) { MobPushUtil.deleteAlias(); SharedPreferencesUtil.setStringValue(Constants.isSetTag, "0"); }); MobPushUtil.addPushReceiver(); - loginSubscription = - EventUtil.instance.on().listen((event) async { + loginSubscription = EventUtil.instance.on().listen((event) async { setAlias(); }); } catch (e, s) { @@ -202,7 +197,7 @@ class _HomePageState extends State List 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 } 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 ), 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 Future _checkLimit(BaseTabModel model) async { if (model.requiredLogin == '1') { - UserInfoModel user = - await Provider.of(context, listen: false).getUserInfoModel(); + UserInfoModel user = await Provider.of(context, listen: false).getUserInfoModel(); print(user.toString()); if (user?.token == null || user.token == '') { print('need login...'); @@ -379,20 +370,15 @@ class _HomePageState extends State 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 void showAlert(String text, BuildContext context) { showDialog( context: context, - builder: (BuildContext context) => CupertinoAlertDialog( - title: new Text("提示"), - content: new Text(text), - actions: [ - new FlatButton( - child: new Text("OK"), - onPressed: () { - Navigator.of(context).pop(); - }, - ) - ])); + builder: (BuildContext context) => CupertinoAlertDialog(title: new Text("提示"), content: new Text(text), actions: [ + new FlatButton( + child: new Text("OK"), + onPressed: () { + Navigator.of(context).pop(); + }, + ) + ])); } @override @@ -515,9 +498,7 @@ class _HomePageState extends State ///设置定向推送 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'];