diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 6e33b809..d2097df7 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -77,7 +77,10 @@ class _HomePageState extends State showBadge: appProvider.messageCenterModel.sysCount==0, position: BadgePosition.topEnd(), child: ColumnActionButton( - onPressed: MessageCenterPage().to, + onPressed: (){ + + MessageCenterPage().to(); + }, title: '消息', path: R.ASSETS_ICONS_ALARM_PNG, ), diff --git a/lib/ui/community/community_views/community_page.dart b/lib/ui/community/community_views/community_page.dart index 8e9e3b7f..b562154c 100644 --- a/lib/ui/community/community_views/community_page.dart +++ b/lib/ui/community/community_views/community_page.dart @@ -1,6 +1,7 @@ // Flutter imports: import 'package:akuCommunity/pages/sign/sign_in_page.dart'; import 'package:akuCommunity/provider/user_provider.dart'; +import 'package:akuCommunity/utils/login_util.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; @@ -58,13 +59,7 @@ class _CommunityPageState extends State ], fab: FloatingActionButton( onPressed: () async { - final userProvider = - Provider.of(context, listen: false); - if (userProvider.isNotLogin) { - BotToast.showText(text: '请先登录'); - Get.to(SignInPage()); - return; - } + if (LoginUtil.isNotLogin) return; bool result = await Get.to(AddNewEventPage()); if (result == true) { switch (_tabController.index) { diff --git a/lib/ui/community/community_views/topic/topic_detail_page.dart b/lib/ui/community/community_views/topic/topic_detail_page.dart index bd826242..e4e02e42 100644 --- a/lib/ui/community/community_views/topic/topic_detail_page.dart +++ b/lib/ui/community/community_views/topic/topic_detail_page.dart @@ -2,6 +2,7 @@ import 'package:akuCommunity/pages/sign/sign_in_page.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/ui/community/community_views/add_new_event_page.dart'; +import 'package:akuCommunity/utils/login_util.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; @@ -41,13 +42,7 @@ class _TopicDetailPageState extends State { floatingActionButton: FloatingActionButton( heroTag: 'event_add', onPressed: () async { - final userProvider = - Provider.of(context, listen: false); - if (userProvider.isNotLogin) { - BotToast.showText(text: '请先登录'); - Get.to(SignInPage()); - return; - } + if (LoginUtil.isNotLogin) return; bool result = await Get.to(AddNewEventPage()); }, child: Icon(Icons.add), diff --git a/lib/ui/community/community_views/widgets/chat_card.dart b/lib/ui/community/community_views/widgets/chat_card.dart index 424ce98e..88a9f4e5 100644 --- a/lib/ui/community/community_views/widgets/chat_card.dart +++ b/lib/ui/community/community_views/widgets/chat_card.dart @@ -3,6 +3,7 @@ import 'dart:math'; // Flutter imports: import 'package:akuCommunity/pages/sign/sign_in_page.dart'; +import 'package:akuCommunity/utils/login_util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -106,13 +107,7 @@ class _ChatCardState extends State { color: Color(0xFFD8D8D8), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onPressed: () { - final userProvider = - Provider.of(context, listen: false); - if (userProvider.isNotLogin) { - BotToast.showText(text: '请先登录'); - Get.to(SignInPage()); - return; - } + if (LoginUtil.isNotLogin) return; BotToast.showAttachedWidget( targetContext: context, preferDirection: PreferDirection.leftCenter, @@ -322,6 +317,7 @@ class _ChatCardState extends State { ]; }, onSelected: (_) async { + if (LoginUtil.isNotLogin) return; VoidCallback cancel = BotToast.showLoading(); await Future.delayed( Duration(milliseconds: 500 + Random().nextInt(500))); diff --git a/lib/utils/login_util.dart b/lib/utils/login_util.dart new file mode 100644 index 00000000..db24667e --- /dev/null +++ b/lib/utils/login_util.dart @@ -0,0 +1,29 @@ +import 'package:akuCommunity/pages/sign/sign_in_page.dart'; +import 'package:akuCommunity/provider/user_provider.dart'; +import 'package:bot_toast/bot_toast.dart'; +import 'package:get/get.dart'; +import 'package:provider/provider.dart'; + +/// | 名称 | 函数 | +/// |-----|------| +/// | 验证登录(登录状态)| LoginnUtil.isLogin | +/// | 验证登录(未登陆状态) | LoginnUtil.isNotLogin | +class LoginUtil { + /// 验证登录(登录状态) + /// + /// 未登陆状态用户跳转到登录页面 + static bool get isLogin { + final userProvider = Provider.of(Get.context, listen: false); + if (userProvider.isNotLogin) { + BotToast.showText(text: '请先登录'); + Get.to(SignInPage()); + return false; + } + return true; + } + + /// 验证登录(未登陆状态) + /// + /// 未登陆状态用户跳转到登录页面 + static bool get isNotLogin => !isLogin; +}