重构登录验证

hmxc
小赖 4 years ago
parent 5ff72035cd
commit 487a57ad9e

@ -77,7 +77,10 @@ class _HomePageState extends State<HomePage>
showBadge: appProvider.messageCenterModel.sysCount==0, showBadge: appProvider.messageCenterModel.sysCount==0,
position: BadgePosition.topEnd(), position: BadgePosition.topEnd(),
child: ColumnActionButton( child: ColumnActionButton(
onPressed: MessageCenterPage().to, onPressed: (){
MessageCenterPage().to();
},
title: '消息', title: '消息',
path: R.ASSETS_ICONS_ALARM_PNG, path: R.ASSETS_ICONS_ALARM_PNG,
), ),

@ -1,6 +1,7 @@
// Flutter imports: // Flutter imports:
import 'package:akuCommunity/pages/sign/sign_in_page.dart'; import 'package:akuCommunity/pages/sign/sign_in_page.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/login_util.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -58,13 +59,7 @@ class _CommunityPageState extends State<CommunityPage>
], ],
fab: FloatingActionButton( fab: FloatingActionButton(
onPressed: () async { onPressed: () async {
final userProvider = if (LoginUtil.isNotLogin) return;
Provider.of<UserProvider>(context, listen: false);
if (userProvider.isNotLogin) {
BotToast.showText(text: '请先登录');
Get.to(SignInPage());
return;
}
bool result = await Get.to(AddNewEventPage()); bool result = await Get.to(AddNewEventPage());
if (result == true) { if (result == true) {
switch (_tabController.index) { switch (_tabController.index) {

@ -2,6 +2,7 @@
import 'package:akuCommunity/pages/sign/sign_in_page.dart'; import 'package:akuCommunity/pages/sign/sign_in_page.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/ui/community/community_views/add_new_event_page.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:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -41,13 +42,7 @@ class _TopicDetailPageState extends State<TopicDetailPage> {
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
heroTag: 'event_add', heroTag: 'event_add',
onPressed: () async { onPressed: () async {
final userProvider = if (LoginUtil.isNotLogin) return;
Provider.of<UserProvider>(context, listen: false);
if (userProvider.isNotLogin) {
BotToast.showText(text: '请先登录');
Get.to(SignInPage());
return;
}
bool result = await Get.to(AddNewEventPage()); bool result = await Get.to(AddNewEventPage());
}, },
child: Icon(Icons.add), child: Icon(Icons.add),

@ -3,6 +3,7 @@ import 'dart:math';
// Flutter imports: // Flutter imports:
import 'package:akuCommunity/pages/sign/sign_in_page.dart'; import 'package:akuCommunity/pages/sign/sign_in_page.dart';
import 'package:akuCommunity/utils/login_util.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -106,13 +107,7 @@ class _ChatCardState extends State<ChatCard> {
color: Color(0xFFD8D8D8), color: Color(0xFFD8D8D8),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () { onPressed: () {
final userProvider = if (LoginUtil.isNotLogin) return;
Provider.of<UserProvider>(context, listen: false);
if (userProvider.isNotLogin) {
BotToast.showText(text: '请先登录');
Get.to(SignInPage());
return;
}
BotToast.showAttachedWidget( BotToast.showAttachedWidget(
targetContext: context, targetContext: context,
preferDirection: PreferDirection.leftCenter, preferDirection: PreferDirection.leftCenter,
@ -322,6 +317,7 @@ class _ChatCardState extends State<ChatCard> {
]; ];
}, },
onSelected: (_) async { onSelected: (_) async {
if (LoginUtil.isNotLogin) return;
VoidCallback cancel = BotToast.showLoading(); VoidCallback cancel = BotToast.showLoading();
await Future.delayed( await Future.delayed(
Duration(milliseconds: 500 + Random().nextInt(500))); Duration(milliseconds: 500 + Random().nextInt(500)));

@ -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<UserProvider>(Get.context, listen: false);
if (userProvider.isNotLogin) {
BotToast.showText(text: '请先登录');
Get.to(SignInPage());
return false;
}
return true;
}
/// ()
///
///
static bool get isNotLogin => !isLogin;
}
Loading…
Cancel
Save