diff --git a/lib/common/core/user_util.dart b/lib/common/core/user_util.dart index c990c45..018f15f 100644 --- a/lib/common/core/user_util.dart +++ b/lib/common/core/user_util.dart @@ -63,8 +63,8 @@ class UserUtil { pushNamedAndRemoveUntil(AppRouteName.login, (route) => false, arguments: {'showPasswordPage': showPasswordLoginPage}); } - // 是否有游戏权限 - static bool hasGamePermission() { + // 是否有权限 + static bool hasPermission() { return _userEntity?.valid ?? false; } diff --git a/lib/pages/home/view.dart b/lib/pages/home/view.dart index 4dc098d..7f9b843 100644 --- a/lib/pages/home/view.dart +++ b/lib/pages/home/view.dart @@ -1,7 +1,5 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_app_update/azhon_app_update.dart'; import 'package:flutter_app_update/update_model.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -69,11 +67,9 @@ class _HomePageView extends StatelessWidget { Expanded( child: GestureDetector( onTap: () { - if (UserUtil.isLogined()) { + _checkPermission(() { pushNamed(AppRouteName.courseUnit); - } else { - pushNamed(AppRouteName.login); - } + }); }, child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -105,30 +101,9 @@ class _HomePageView extends StatelessWidget { 'WQF ModuleSelectPage BlocBuilder state: $userState'); return GestureDetector( onTap: () { - //如果没登录先登录 - if (UserUtil.isLogined()) { - if (AppConfigHelper - .shouldHidePay()) { - pushNamed(AppRouteName.games); - } else { - if (UserUtil - .hasGamePermission()) { - pushNamed(AppRouteName.games); - } else { - showTwoActionDialog( - '提示', '忽略', '去续费', - '您的课程已到期,请快快续费继续学习吧!', - leftTap: () { - popPage(); - }, rightTap: () { - popPage(); - pushNamed(AppRouteName.shop); - }); - } - } - } else { - pushNamed(AppRouteName.login); - } + _checkPermission(() { + pushNamed(AppRouteName.games); + }); }, child: Column( mainAxisAlignment: MainAxisAlignment @@ -168,6 +143,30 @@ class _HomePageView extends StatelessWidget { }); + _checkPermission(VoidCallback onAllowed) { + if (UserUtil.isLogined()) { + if (AppConfigHelper.shouldHidePay()) { + onAllowed(); + } else { + if (UserUtil.hasPermission()) { + onAllowed(); + } else { + showTwoActionDialog('提示', '忽略', '去续费', + '您的课程已到期,请快快续费继续学习吧!', leftTap: () { + popPage(); + }, rightTap: () { + popPage(); + pushNamed(AppRouteName.shop); + }); + } + } + } else { + //如果没登录先登录 + pushNamed(AppRouteName.login); + } + } + + ///Flutter侧处理升级对话框 ///[forcedUpgrade] 是否强制升级 _showUpdateDialog(BuildContext context, bool forcedUpgrade,