重构登录验证

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

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

@ -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<CommunityPage>
],
fab: FloatingActionButton(
onPressed: () async {
final userProvider =
Provider.of<UserProvider>(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) {

@ -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<TopicDetailPage> {
floatingActionButton: FloatingActionButton(
heroTag: 'event_add',
onPressed: () async {
final userProvider =
Provider.of<UserProvider>(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),

@ -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<ChatCard> {
color: Color(0xFFD8D8D8),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {
final userProvider =
Provider.of<UserProvider>(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<ChatCard> {
];
},
onSelected: (_) async {
if (LoginUtil.isNotLogin) return;
VoidCallback cancel = BotToast.showLoading();
await Future.delayed(
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