未登陆用户前端权限限制🚫

hmxc
小赖 4 years ago
parent 7ed5130ee2
commit ee3ae0531d

@ -15,16 +15,9 @@ import 'package:akuCommunity/utils/network/base_model.dart';
import 'package:akuCommunity/utils/network/net_util.dart';
class UserProvider extends ChangeNotifier {
//
bool _isSigned = false;
get isSigned => _isSigned;
setisSigned(bool state) {
_isSigned = state;
notifyListeners();
}
bool _isLogin = false;
bool get isLogin => _isLogin;
bool get isNotLogin => !_isLogin;
Future setLogin(int token) async {
_isLogin = true;
NetUtil().dio.options.headers.putIfAbsent('App-Admin-Token', () => token);

@ -1,4 +1,7 @@
// Flutter imports:
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:flutter/material.dart';
// Package imports:
@ -14,6 +17,7 @@ import 'package:akuCommunity/utils/headers.dart';
import 'package:akuCommunity/widget/bee_scaffold.dart';
import 'package:akuCommunity/widget/buttons/column_action_button.dart';
import 'package:akuCommunity/widget/tab_bar/bee_tab_bar.dart';
import 'package:provider/provider.dart';
class CommunityPage extends StatefulWidget {
CommunityPage({Key key}) : super(key: key);
@ -54,6 +58,13 @@ 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;
}
bool result = await Get.to(AddNewEventPage());
if (result == true) {
switch (_tabController.index) {

@ -1,4 +1,8 @@
// Flutter imports:
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:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
// Package imports:
@ -11,6 +15,8 @@ import 'package:akuCommunity/model/community/event_item_model.dart';
import 'package:akuCommunity/pages/things_page/widget/bee_list_view.dart';
import 'package:akuCommunity/ui/community/community_views/topic/topic_sliver_header.dart';
import 'package:akuCommunity/ui/community/community_views/widgets/chat_card.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
class TopicDetailPage extends StatefulWidget {
final CommunityTopicModel model;
@ -34,7 +40,16 @@ class _TopicDetailPageState extends State<TopicDetailPage> {
return Scaffold(
floatingActionButton: FloatingActionButton(
heroTag: 'event_add',
onPressed: () {},
onPressed: () async {
final userProvider =
Provider.of<UserProvider>(context, listen: false);
if (userProvider.isNotLogin) {
BotToast.showText(text: '请先登录');
Get.to(SignInPage());
return;
}
bool result = await Get.to(AddNewEventPage());
},
child: Icon(Icons.add),
),
body: BeeListView(

@ -2,6 +2,7 @@
import 'dart:math';
// Flutter imports:
import 'package:akuCommunity/pages/sign/sign_in_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@ -105,6 +106,13 @@ 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;
}
BotToast.showAttachedWidget(
targetContext: context,
preferDirection: PreferDirection.leftCenter,

Loading…
Cancel
Save