From a024b34a4f3c692e86f44aa03bef61a4ef166bd8 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 13:43:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A4=BE=E5=8C=BA=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E3=80=81=E5=85=AC=E5=91=8A=E5=8D=A1=E7=89=87=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community_views/community_page.dart | 28 ++++++++++++++++--- .../community_views/my_community_view.dart | 9 ++++-- .../community_views/new_community_view.dart | 9 ++++-- .../topic/topic_community_view.dart | 7 +++-- .../widgets/my_event_card.dart | 7 ++++- lib/ui/community/notice/notice_card.dart | 2 +- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/lib/ui/community/community_views/community_page.dart b/lib/ui/community/community_views/community_page.dart index 1e93c3d5..502b81d8 100644 --- a/lib/ui/community/community_views/community_page.dart +++ b/lib/ui/community/community_views/community_page.dart @@ -25,6 +25,11 @@ class _CommunityPageState extends State with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { TabController _tabController; List _tabs = ['最新', '话题', '我的']; + GlobalKey topicKey = + GlobalKey(); + GlobalKey myKey = GlobalKey(); + GlobalKey newKey = GlobalKey(); + @override void initState() { super.initState(); @@ -47,7 +52,22 @@ class _CommunityPageState extends State ), ], fab: FloatingActionButton( - onPressed: () => Get.to(AddNewEventPage()), + onPressed: () async { + bool result = await Get.to(AddNewEventPage()); + if (result == true) { + switch (_tabController.index) { + case 0: + newKey.currentState.refresh(); + break; + case 1: + topicKey.currentState.refresh(); + break; + case 2: + myKey.currentState.refresh(); + break; + } + } + }, heroTag: 'event_add', child: Icon(Icons.add), ), @@ -64,9 +84,9 @@ class _CommunityPageState extends State ), body: TabBarView( children: [ - NewCommunityView(), - TopicCommunityView(), - MyCommunityView(), + NewCommunityView(key: newKey), + TopicCommunityView(key: topicKey), + MyCommunityView(key: myKey), ], controller: _tabController, ), diff --git a/lib/ui/community/community_views/my_community_view.dart b/lib/ui/community/community_views/my_community_view.dart index 6e99a1ed..5c128a9f 100644 --- a/lib/ui/community/community_views/my_community_view.dart +++ b/lib/ui/community/community_views/my_community_view.dart @@ -15,12 +15,17 @@ class MyCommunityView extends StatefulWidget { MyCommunityView({Key key}) : super(key: key); @override - _MyCommunityViewState createState() => _MyCommunityViewState(); + MyCommunityViewState createState() => MyCommunityViewState(); } -class _MyCommunityViewState extends State +class MyCommunityViewState extends State with AutomaticKeepAliveClientMixin { EasyRefreshController _refreshController = EasyRefreshController(); + + refresh() { + _refreshController?.callRefresh(); + } + @override Widget build(BuildContext context) { super.build(context); diff --git a/lib/ui/community/community_views/new_community_view.dart b/lib/ui/community/community_views/new_community_view.dart index 1d29dca6..d7ad3e4a 100644 --- a/lib/ui/community/community_views/new_community_view.dart +++ b/lib/ui/community/community_views/new_community_view.dart @@ -14,12 +14,17 @@ class NewCommunityView extends StatefulWidget { NewCommunityView({Key key}) : super(key: key); @override - _NewCommunityViewState createState() => _NewCommunityViewState(); + NewCommunityViewState createState() => NewCommunityViewState(); } -class _NewCommunityViewState extends State +class NewCommunityViewState extends State with AutomaticKeepAliveClientMixin { EasyRefreshController _refreshController = EasyRefreshController(); + + refresh() { + _refreshController?.callRefresh(); + } + @override void dispose() { _refreshController?.dispose(); diff --git a/lib/ui/community/community_views/topic/topic_community_view.dart b/lib/ui/community/community_views/topic/topic_community_view.dart index 053bd06f..e23df610 100644 --- a/lib/ui/community/community_views/topic/topic_community_view.dart +++ b/lib/ui/community/community_views/topic/topic_community_view.dart @@ -19,12 +19,15 @@ class TopicCommunityView extends StatefulWidget { TopicCommunityView({Key key}) : super(key: key); @override - _TopicCommunityViewState createState() => _TopicCommunityViewState(); + TopicCommunityViewState createState() => TopicCommunityViewState(); } -class _TopicCommunityViewState extends State +class TopicCommunityViewState extends State with AutomaticKeepAliveClientMixin { EasyRefreshController _refreshController = EasyRefreshController(); + refresh() { + _refreshController?.callRefresh(); + } _buildItem(CommunityTopicModel model) { return MaterialButton( diff --git a/lib/ui/community/community_views/widgets/my_event_card.dart b/lib/ui/community/community_views/widgets/my_event_card.dart index 90fe2457..20391928 100644 --- a/lib/ui/community/community_views/widgets/my_event_card.dart +++ b/lib/ui/community/community_views/widgets/my_event_card.dart @@ -28,6 +28,11 @@ class MyEventCard extends StatelessWidget { BeeDateUtil get beeDate => BeeDateUtil(model.date); + bool get sameDay => + model.date.year == (preModel?.date?.year ?? 0) && + model.date.month == (preModel?.date?.month ?? 0) && + model.date.day == (preModel?.date?.day ?? 0); + Widget title() { if (beeDate.sameDay) return '今天'.text.size(52.sp).bold.make(); if (beeDate.isYesterday) @@ -65,7 +70,7 @@ class MyEventCard extends StatelessWidget { width: 200.w, padding: EdgeInsets.only(left: 32.w), alignment: Alignment.topLeft, - child: beeDate.sameDay ? title() : SizedBox(), + child: sameDay ? SizedBox() : title(), ), model.imgUrl.length == 0 ? SizedBox(height: 152.w) diff --git a/lib/ui/community/notice/notice_card.dart b/lib/ui/community/notice/notice_card.dart index ee7ec89c..ac3c1337 100644 --- a/lib/ui/community/notice/notice_card.dart +++ b/lib/ui/community/notice/notice_card.dart @@ -81,7 +81,7 @@ class NoticeCard extends StatelessWidget { width: 200.w, padding: EdgeInsets.only(left: 32.w), alignment: Alignment.topLeft, - child: sameDay ? title() : SizedBox(), + child: sameDay ? SizedBox() : title(), ), model.imgUrls.length == 0 ? SizedBox(height: 152.w)