From ee3ae0531d117e8132683ec4426e067c5e58e647 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 12 Mar 2021 10:33:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E7=99=BB=E9=99=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E6=9D=83=E9=99=90=E9=99=90=E5=88=B6?= =?UTF-8?q?=F0=9F=9A=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/provider/user_provider.dart | 9 +-------- .../community_views/community_page.dart | 11 +++++++++++ .../topic/topic_detail_page.dart | 17 ++++++++++++++++- .../community_views/widgets/chat_card.dart | 8 ++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index 2c44811f..f2a160c5 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -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); diff --git a/lib/ui/community/community_views/community_page.dart b/lib/ui/community/community_views/community_page.dart index b4c83dff..8e9e3b7f 100644 --- a/lib/ui/community/community_views/community_page.dart +++ b/lib/ui/community/community_views/community_page.dart @@ -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 ], fab: FloatingActionButton( onPressed: () async { + final userProvider = + Provider.of(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) { 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 c6af2005..bd826242 100644 --- a/lib/ui/community/community_views/topic/topic_detail_page.dart +++ b/lib/ui/community/community_views/topic/topic_detail_page.dart @@ -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 { return Scaffold( floatingActionButton: FloatingActionButton( heroTag: 'event_add', - onPressed: () {}, + onPressed: () async { + final userProvider = + Provider.of(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( diff --git a/lib/ui/community/community_views/widgets/chat_card.dart b/lib/ui/community/community_views/widgets/chat_card.dart index bf1b55cb..424ce98e 100644 --- a/lib/ui/community/community_views/widgets/chat_card.dart +++ b/lib/ui/community/community_views/widgets/chat_card.dart @@ -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 { color: Color(0xFFD8D8D8), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onPressed: () { + final userProvider = + Provider.of(context, listen: false); + if (userProvider.isNotLogin) { + BotToast.showText(text: '请先登录'); + Get.to(SignInPage()); + return; + } BotToast.showAttachedWidget( targetContext: context, preferDirection: PreferDirection.leftCenter,