From ed07cee5ff27b327d2df9dad8b1eaef5958eba3e Mon Sep 17 00:00:00 2001 From: "23028876916@qq.com" Date: Thu, 6 May 2021 18:50:04 +0800 Subject: [PATCH] =?UTF-8?q?0506=20=20=E9=A6=96=E9=A1=B5=E5=BA=95=E9=83=A8?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=B7=BB=E5=8A=A0=E7=82=B9=E5=87=BB=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E9=80=9A=E7=9F=A5=E6=8E=A7=E5=88=B6=E6=8A=96=E5=88=B8?= =?UTF-8?q?=E7=9A=84=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/home_page/home_page.dart | 59 ++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index cb0c5ed..07e5156 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -53,7 +53,8 @@ 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'); @@ -72,7 +73,8 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker //如果登出则重新打开首页 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"); @@ -123,7 +125,8 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker //app后台杀死时候的还原 Moblink.restoreScene(_restore); // 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来) - eventChannelSubscription = _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); + eventChannelSubscription = + _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); logOutSubscription = EventUtil.instance.on().listen((event) { MobPushUtil.deleteAlias(); @@ -131,7 +134,8 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker }); MobPushUtil.addPushReceiver(); - loginSubscription = EventUtil.instance.on().listen((event) async { + loginSubscription = + EventUtil.instance.on().listen((event) async { setAlias(); }); } catch (e, s) { @@ -190,6 +194,8 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker } List contentWidgets = tabs.map((item) { BaseTabModel model = BaseTabModel.fromJson(item); + //首页底部创建的item,把抖券判断置true + item['is_bottom_video']=true; return PageFactory.create(model.skipIdentifier, item); }).toList(); if (_currentIndex >= contentWidgets.length) { @@ -229,7 +235,9 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker ), 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)), ))); } } @@ -251,6 +259,7 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker elevation: 0, onTap: ((index) async { BaseTabModel model = BaseTabModel.fromJson(tabs[index]); + if (await _checkLimit(model)) { ///避免同一个页面多次点击多次重绘 if (_currentIndex == index) { @@ -264,6 +273,7 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker setState(() { _currentIndex = index; }); + EventUtil.instance.fire(model?.skipIdentifier); } } }), @@ -330,7 +340,8 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker 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...'); @@ -351,15 +362,20 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker 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) { ///啥也不干 @@ -449,14 +465,17 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker 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 @@ -478,7 +497,9 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker ///设置定向推送 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']; @@ -534,4 +555,4 @@ abstract class LifeState extends State with RouteAw void onResume(); void onPaused(); -} \ No newline at end of file +}