From 332c12cfaeb40ba44f9e50e8c1f07b7d2f25da81 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 10:48:03 +0800 Subject: [PATCH 1/6] fix bee list view load issue. --- lib/pages/things_page/widget/bee_list_view.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pages/things_page/widget/bee_list_view.dart b/lib/pages/things_page/widget/bee_list_view.dart index 0628eb05..12a878c7 100644 --- a/lib/pages/things_page/widget/bee_list_view.dart +++ b/lib/pages/things_page/widget/bee_list_view.dart @@ -100,6 +100,7 @@ class _BeeListViewState extends State { params: _params, ); _models = widget.convert(_model); + widget.controller.resetLoadState(); setState(() {}); }, firstRefresh: true, From 1d32e8089192e20ba2457d2dd1afde942712a7a0 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 11:55:03 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=98=BE=E7=A4=BA=EF=BC=8C=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 3 +++ .../community_views/new_community_view.dart | 3 +++ .../community_views/topic/topic_detail_page.dart | 3 +++ .../community_views/widgets/chat_card.dart | 12 ++++++++++-- .../community_views/widgets/my_event_card.dart | 9 ++++++--- lib/ui/community/notice/notice_card.dart | 2 +- lib/utils/bee_date_util.dart | 14 ++++++++------ lib/widget/picker/bee_image_preview.dart | 9 +++++---- 8 files changed, 39 insertions(+), 16 deletions(-) diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 42f6f6b5..4b270c3e 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -187,6 +187,9 @@ class _Community { ///社区话题:我的动态 String get myEvent => '/user/gambit/myTidings'; + + ///社区话题:假删除主题信息(只能删除自己的) + String get deleteMyEvent => '/user/gambit/falseDelete'; } class _Upload { diff --git a/lib/ui/community/community_views/new_community_view.dart b/lib/ui/community/community_views/new_community_view.dart index ec672982..1d29dca6 100644 --- a/lib/ui/community/community_views/new_community_view.dart +++ b/lib/ui/community/community_views/new_community_view.dart @@ -49,6 +49,9 @@ class _NewCommunityViewState extends State headImg: item.headSculptureImgUrl, themeId: item.id, initLike: item.isLike == 1, + onDelete: () { + _refreshController.callRefresh(); + }, ); }, itemCount: items.length, 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 5e415359..abfb4a63 100644 --- a/lib/ui/community/community_views/topic/topic_detail_page.dart +++ b/lib/ui/community/community_views/topic/topic_detail_page.dart @@ -73,6 +73,9 @@ class _TopicDetailPageState extends State { contentImg: item.imgUrls, date: item.date, id: item.createId, + onDelete: () { + _refreshController.callRefresh(); + }, ); }, childCount: items.length, diff --git a/lib/ui/community/community_views/widgets/chat_card.dart b/lib/ui/community/community_views/widgets/chat_card.dart index b5e2be2c..a88a13b6 100644 --- a/lib/ui/community/community_views/widgets/chat_card.dart +++ b/lib/ui/community/community_views/widgets/chat_card.dart @@ -33,6 +33,8 @@ class ChatCard extends StatefulWidget { final int themeId; + final VoidCallback onDelete; + ChatCard({ Key key, @required this.name, @@ -44,6 +46,7 @@ class ChatCard extends StatefulWidget { @required this.id, @required this.content, @required this.themeId, + this.onDelete, }) : super(key: key); @override @@ -136,7 +139,7 @@ class _ChatCardState extends State { cancel(); await NetUtil().get( API.community.like, - params: {'themeId': widget.id}, + params: {'themeId': widget.themeId}, showMessage: true, ); setState(() { @@ -291,7 +294,12 @@ class _ChatCardState extends State { )); if (result == true) { - //TODO delete operation + await NetUtil().get( + API.community.deleteMyEvent, + params: {'themeId': widget.themeId}, + showMessage: true, + ); + if (widget.onDelete != null) widget.onDelete(); } }, child: '删除'.text.black.size(28.sp).make(), 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 516851ed..90fe2457 100644 --- a/lib/ui/community/community_views/widgets/my_event_card.dart +++ b/lib/ui/community/community_views/widgets/my_event_card.dart @@ -65,19 +65,22 @@ class MyEventCard extends StatelessWidget { width: 200.w, padding: EdgeInsets.only(left: 32.w), alignment: Alignment.topLeft, - child: beeDate.sameDay ? SizedBox() : title(), + child: beeDate.sameDay ? title() : SizedBox(), ), model.imgUrl.length == 0 ? SizedBox(height: 152.w) : GestureDetector( onTap: () { Get.to( - BeeImagePreview.path(path: model.imgUrl.first.url), + BeeImagePreview.path( + path: model.imgUrl.first.url, + tag: API.image(model.imgUrl.first.url), + ), opaque: false, ); }, child: Hero( - tag: model.imgUrl.first.url, + tag: API.image(model.imgUrl.first.url), child: Container( clipBehavior: Clip.antiAlias, decoration: BoxDecoration( diff --git a/lib/ui/community/notice/notice_card.dart b/lib/ui/community/notice/notice_card.dart index ac3c1337..ee7ec89c 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 ? SizedBox() : title(), + child: sameDay ? title() : SizedBox(), ), model.imgUrls.length == 0 ? SizedBox(height: 152.w) diff --git a/lib/utils/bee_date_util.dart b/lib/utils/bee_date_util.dart index d28e14fa..3837de22 100644 --- a/lib/utils/bee_date_util.dart +++ b/lib/utils/bee_date_util.dart @@ -8,12 +8,14 @@ class BeeDateUtil { bool get sameYear => _now.year == this.date.year; bool get sameMonth => sameYear && _now.month == this.date.month; bool get sameDay => sameMonth && _now.day == this.date.day; - bool get isYesterday => (DateTime(_now.year, _now.month, _now.day - 1) - .compareTo(DateTime(this.date.year)) == - 0); - bool get isDoubleYesterday => (DateTime(_now.year, _now.month, _now.day - 2) - .compareTo(DateTime(this.date.year)) == - 0); + bool get isYesterday => + (DateTime(_now.year, _now.month, _now.day - 1).compareTo( + DateTime(this.date.year, this.date.month, this.date.day)) == + 0); + bool get isDoubleYesterday => + (DateTime(_now.year, _now.month, _now.day - 2).compareTo( + DateTime(this.date.year, this.date.month, this.date.day)) == + 0); String get timeAgo { Duration duration = _now.difference(date); diff --git a/lib/widget/picker/bee_image_preview.dart b/lib/widget/picker/bee_image_preview.dart index 4ad8561e..b9bd46b5 100644 --- a/lib/widget/picker/bee_image_preview.dart +++ b/lib/widget/picker/bee_image_preview.dart @@ -15,11 +15,12 @@ import 'package:akuCommunity/constants/api.dart'; class BeeImagePreview extends StatefulWidget { final File file; final String path; - BeeImagePreview.file({Key key, @required this.file}) + final String tag; + BeeImagePreview.file({Key key, @required this.file, this.tag}) : path = null, super(key: key); - BeeImagePreview.path({Key key, @required this.path}) + BeeImagePreview.path({Key key, @required this.path, this.tag}) : file = null, super(key: key); @@ -31,7 +32,7 @@ class _BeeImagePreviewState extends State { Widget get image { if (widget.file == null) return Hero( - tag: widget.path, + tag: widget.tag ?? widget.path, child: FadeInImage.assetNetwork( placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, image: API.image(widget.path), @@ -39,7 +40,7 @@ class _BeeImagePreviewState extends State { ); else return Hero( - tag: widget.file.hashCode, + tag: widget.tag ?? widget.file.hashCode, child: Image.file(widget.file), ); } From a024b34a4f3c692e86f44aa03bef61a4ef166bd8 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 13:43:47 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E3=80=81=E5=85=AC=E5=91=8A=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E7=9A=84=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) From c612dc46f185716a90a73c48d226f41573982f89 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 14:39:48 +0800 Subject: [PATCH 4/6] remove sh*t popup --- lib/pages/one_alarm/alarm_detail_page.dart | 25 +++++ lib/pages/one_alarm/widget/alarm_page.dart | 51 +--------- .../one_alarm/widget/explain_template.dart | 93 ------------------- pubspec.lock | 7 -- pubspec.yaml | 2 - 5 files changed, 30 insertions(+), 148 deletions(-) create mode 100644 lib/pages/one_alarm/alarm_detail_page.dart delete mode 100644 lib/pages/one_alarm/widget/explain_template.dart diff --git a/lib/pages/one_alarm/alarm_detail_page.dart b/lib/pages/one_alarm/alarm_detail_page.dart new file mode 100644 index 00000000..0898ca91 --- /dev/null +++ b/lib/pages/one_alarm/alarm_detail_page.dart @@ -0,0 +1,25 @@ +import 'package:akuCommunity/utils/headers.dart'; +import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:flutter/material.dart'; + +class AlarmDetailPage extends StatelessWidget { + const AlarmDetailPage({Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: '功能说明', + body: ListView( + padding: EdgeInsets.all(32.w), + children: [ + '一键报警'.text.size(32.sp).bold.make(), + 20.hb, + '点击“呼叫110”后,您可以直接拨打本地110。页面中提供了您当前所在位置,以便您与警方沟通。(GPS信号弱时,位置可能存在偏移)' + .text + .size(28.sp) + .make(), + ], + ), + ); + } +} diff --git a/lib/pages/one_alarm/widget/alarm_page.dart b/lib/pages/one_alarm/widget/alarm_page.dart index 5d93b905..aacf625f 100644 --- a/lib/pages/one_alarm/widget/alarm_page.dart +++ b/lib/pages/one_alarm/widget/alarm_page.dart @@ -1,18 +1,18 @@ // Flutter imports: +import 'package:akuCommunity/pages/one_alarm/alarm_detail_page.dart'; import 'package:flutter/material.dart'; // Package imports: import 'package:amap_location_fluttify/amap_location_fluttify.dart'; import 'package:amap_map_fluttify/amap_map_fluttify.dart'; -import 'package:flutter_beautiful_popup/main.dart'; import 'package:flutter_icons/flutter_icons.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:velocity_x/velocity_x.dart'; // Project imports: -import 'package:akuCommunity/pages/one_alarm/widget/explain_template.dart'; import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; @@ -41,41 +41,6 @@ class _AlarmPageState extends State { AmapController _amapController; Location _location; - void showExplain(BuildContext context) { - final popup = BeautifulPopup.customize( - context: context, - build: (options) => ExplainTemplate(options), - ); - popup.show( - title: Text( - '功能说明', - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 32.sp, - color: Color(0xff15c0ec), - ), - ), - content: Text( - '点击“呼叫110”后,您可以直接拨打本地110。页面中提供了您当前所在位置,以便您与警方沟通。(GPS信号弱时,位置可能存在偏移)', - style: TextStyle( - fontSize: 28.sp, - color: Color(0xff666666), - ), - ), - actions: [ - MaterialButton( - color: Color(0xff15c0ec), - textColor: Colors.white, - shape: RoundedRectangleBorder( - side: BorderSide.none, - borderRadius: BorderRadius.all(Radius.circular(50))), - child: Text('关闭'), - onPressed: Navigator.of(context).pop, - ) - ], - close: SizedBox()); - } - @override void initState() { super.initState(); @@ -96,15 +61,9 @@ class _AlarmPageState extends State { return BeeScaffold( title: '一键报警', actions: [ - InkWell( - onTap: () { - showExplain(context); - }, - child: Container( - padding: EdgeInsets.fromLTRB(32.w, 28.w, 32.w, 20.w), - child: '全部已读'.text.black.size(28.sp).make(), - alignment: Alignment.center, - ), + MaterialButton( + onPressed: () => Get.to(AlarmDetailPage()), + child: '功能说明'.text.black.size(28.sp).make(), ) ], body: Stack( diff --git a/lib/pages/one_alarm/widget/explain_template.dart b/lib/pages/one_alarm/widget/explain_template.dart deleted file mode 100644 index 4836ba9c..00000000 --- a/lib/pages/one_alarm/widget/explain_template.dart +++ /dev/null @@ -1,93 +0,0 @@ -// Dart imports: -import 'dart:ui'; - -// Flutter imports: -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; - -// Package imports: -import 'package:flutter_beautiful_popup/main.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; - -// Project imports: -import 'package:akuCommunity/utils/headers.dart'; - -class ExplainTemplate extends BeautifulPopupTemplate { - final BeautifulPopup options; - ExplainTemplate(this.options) : super(options); - - @override - final illustrationPath = 'img/bg/authentication.png'; - @override - Color get primaryColor => options.primaryColor ?? Color(0xff15c0ec); - @override - final maxWidth = 400.w; - @override - final maxHeight = 617.w; - @override - final bodyMargin = 0; - @override - get layout { - return [ - Positioned( - child: background, - ), - Positioned( - top: percentH(32), - child: title, - ), - Positioned( - top: percentH(42), - left: percentW(10), - right: percentW(10), - height: percentH(actions == null ? 52 : 38), - child: content, - ), - Positioned( - bottom: percentW(8), - left: percentW(8), - right: percentW(8), - child: actions ?? Container(), - ), - ]; - } -} - -// class Explain extends StatelessWidget { -// const Explain({Key key}) : super(key: key); - -// @override -// Widget build(BuildContext context) { -// return Container( -// color: Colors.white, -// padding: EdgeInsets.only( -// top: 32.w, -// left: 32.w, -// right: 32.w, -// ), -// child: Column( -// crossAxisAlignment: CrossAxisAlignment.start, -// children: [ -// Text( -// '一键报警', -// style: TextStyle( -// fontSize: BaseStyle.fontSize32, -// color: ktextPrimary, -// fontWeight: FontWeight.bold, -// ), -// ), -// Container( -// margin: EdgeInsets.only(top: 20.w), -// child: Text( -// '点击“呼叫110”后,您可以直接拨打本地110。页面中提供了您当前所在位置,以便您与警方沟通。(GPS信号弱时,位置可能存在偏移)', -// style: TextStyle( -// fontSize: BaseStyle.fontSize28, -// color: ktextSubColor, -// ), -// ), -// ), -// ], -// ), -// ); -// } -// } diff --git a/pubspec.lock b/pubspec.lock index 4422454d..362f28a6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -328,13 +328,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.6.1" - flutter_beautiful_popup: - dependency: "direct main" - description: - name: flutter_beautiful_popup - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.5.0" flutter_blurhash: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b06b4409..f89c5dd0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,8 +44,6 @@ dependencies: fluro: ^1.6.3 #滑动卡片 font_awesome_flutter: ^8.8.1 - #弹窗 - flutter_beautiful_popup: ^1.5.0 #图片预览 photo_view: ^0.10.2 #图片缓存 From 56bd1ea4818c7c8c3e4713cd27c7ad3e69fc21ca Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 14:40:03 +0800 Subject: [PATCH 5/6] update README FILE --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index cb8145af..29c41dcc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # akuCommunity +[![State-of-the-art Shitcode](https://img.shields.io/static/v1?label=State-of-the-art&message=Shitcode&color=7B5804)](https://github.com/trekhleb/state-of-the-art-shitcode) + ## Getting Started ## Code Contribute From 11f9ce371a84a12e5758febc84d6fc73a474fd72 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 16:01:29 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=82=B9=E8=B5=9E=E5=92=8C=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 3 + lib/model/community/event_item_model.dart | 6 +- .../community_views/event_detail_page.dart | 48 ++++++++++- .../community_views/new_community_view.dart | 2 + .../topic/topic_detail_page.dart | 2 + .../community_views/widgets/chat_card.dart | 83 +++++++++++++++++-- 6 files changed, 132 insertions(+), 12 deletions(-) diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 4b270c3e..9184e833 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -190,6 +190,9 @@ class _Community { ///社区话题:假删除主题信息(只能删除自己的) String get deleteMyEvent => '/user/gambit/falseDelete'; + + ///社区话题:查询主题信息详情 + String get getEventDetail => '/user/gambit/GambitThemeDetail'; } class _Upload { diff --git a/lib/model/community/event_item_model.dart b/lib/model/community/event_item_model.dart index 0de9e1a8..f77b2cb7 100644 --- a/lib/model/community/event_item_model.dart +++ b/lib/model/community/event_item_model.dart @@ -46,7 +46,8 @@ class EventItemModel { json['likeNames'].forEach((v) { likeNames.add(new LikeNames.fromJson(v)); }); - } + } else + likeNames = []; if (json['imgUrls'] != null) { imgUrls = new List(); json['imgUrls'].forEach((v) { @@ -66,7 +67,8 @@ class EventItemModel { json['gambitThemeCommentVoList'].forEach((v) { gambitThemeCommentVoList.add(new GambitThemeCommentVoList.fromJson(v)); }); - } + } else + gambitThemeCommentVoList = []; } Map toJson() { diff --git a/lib/ui/community/community_views/event_detail_page.dart b/lib/ui/community/community_views/event_detail_page.dart index 9be50806..3b730e54 100644 --- a/lib/ui/community/community_views/event_detail_page.dart +++ b/lib/ui/community/community_views/event_detail_page.dart @@ -1,21 +1,67 @@ // Flutter imports: +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/community/event_item_model.dart'; +import 'package:akuCommunity/ui/community/community_views/widgets/chat_card.dart'; +import 'package:akuCommunity/utils/network/base_model.dart'; +import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:flutter/material.dart'; // Project imports: import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; class EventDetailPage extends StatefulWidget { - EventDetailPage({Key key}) : super(key: key); + final int themeId; + EventDetailPage({ + Key key, + @required this.themeId, + }) : super(key: key); @override _EventDetailPageState createState() => _EventDetailPageState(); } class _EventDetailPageState extends State { + EasyRefreshController _refreshController = EasyRefreshController(); + EventItemModel _model; @override Widget build(BuildContext context) { return BeeScaffold( title: '详情', + body: EasyRefresh( + controller: _refreshController, + header: MaterialHeader(), + firstRefresh: true, + onRefresh: () async { + BaseModel model = await NetUtil().get( + API.community.getEventDetail, + params: {'themeId': widget.themeId}, + ); + _model = EventItemModel.fromJson(model.data); + setState(() {}); + }, + child: _model == null + ? SizedBox() + : ListView( + children: [ + ChatCard( + initLike: _model.isLike == 1, + name: _model.createName, + topic: _model.gambitTitle, + headImg: _model.headSculptureImgUrl, + contentImg: _model.imgUrls, + date: _model.date, + id: _model.id, + content: _model.content, + themeId: _model.id, + comments: _model.gambitThemeCommentVoList, + likeNames: _model.likeNames, + hideLine: true, + canTap: false, + ), + ], + ), + ), ); } } diff --git a/lib/ui/community/community_views/new_community_view.dart b/lib/ui/community/community_views/new_community_view.dart index d7ad3e4a..babcf653 100644 --- a/lib/ui/community/community_views/new_community_view.dart +++ b/lib/ui/community/community_views/new_community_view.dart @@ -54,6 +54,8 @@ class NewCommunityViewState extends State headImg: item.headSculptureImgUrl, themeId: item.id, initLike: item.isLike == 1, + comments: item.gambitThemeCommentVoList, + likeNames: item.likeNames, onDelete: () { _refreshController.callRefresh(); }, 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 abfb4a63..b62772f3 100644 --- a/lib/ui/community/community_views/topic/topic_detail_page.dart +++ b/lib/ui/community/community_views/topic/topic_detail_page.dart @@ -76,6 +76,8 @@ class _TopicDetailPageState extends State { onDelete: () { _refreshController.callRefresh(); }, + comments: item.gambitThemeCommentVoList, + likeNames: item.likeNames, ); }, childCount: items.length, diff --git a/lib/ui/community/community_views/widgets/chat_card.dart b/lib/ui/community/community_views/widgets/chat_card.dart index a88a13b6..2edc57cc 100644 --- a/lib/ui/community/community_views/widgets/chat_card.dart +++ b/lib/ui/community/community_views/widgets/chat_card.dart @@ -1,4 +1,5 @@ // Flutter imports: +import 'package:akuCommunity/model/community/event_item_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -35,6 +36,12 @@ class ChatCard extends StatefulWidget { final VoidCallback onDelete; + final List comments; + final List likeNames; + + final bool hideLine; + final bool canTap; + ChatCard({ Key key, @required this.name, @@ -42,11 +49,15 @@ class ChatCard extends StatefulWidget { @required this.headImg, @required this.contentImg, @required this.date, - this.initLike = false, + @required this.initLike, @required this.id, @required this.content, @required this.themeId, this.onDelete, + @required this.comments, + this.hideLine = false, + @required this.likeNames, + this.canTap = true, }) : super(key: key); @override @@ -202,6 +213,57 @@ class _ChatCardState extends State { }); } + _renderLike() { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 16.w), + child: Flex( + direction: Axis.horizontal, + children: [ + Icon(Icons.favorite_border_rounded, size: 24.w), + 14.wb, + ...widget.likeNames + .map((e) => e.name.text.make()) + .toList() + .sepWidget(separate: ','.text.make()), + ], + ), + ); + } + + _renderComment() { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: widget.comments.map((e) { + StringBuffer buffer = StringBuffer(); + buffer.write(e.createName); + if (e.parentName != null) buffer.write('回复${e.parentName}'); + buffer.write(':${e.content}'); + return buffer.toString().text.make(); + }).toList(), + ); + } + + _renderLikeAndComment() { + return Material( + borderRadius: BorderRadius.circular(8.w), + color: Color(0xFFF7F7F7), + child: Padding( + padding: EdgeInsets.all(8.w), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + widget.likeNames.isEmpty ? SizedBox() : _renderLike(), + (widget.likeNames.isNotEmpty && widget.comments.isNotEmpty) + ? Divider(height: 1.w, thickness: 1.w) + : SizedBox(), + widget.comments.isEmpty ? SizedBox() : _renderComment(), + ], + ), + ), + ); + } + @override void initState() { super.initState(); @@ -210,21 +272,22 @@ class _ChatCardState extends State { @override Widget build(BuildContext context) { - final userProvider = Provider.of(context); return DecoratedBox( decoration: BoxDecoration( color: Colors.white, border: Border( bottom: BorderSide( - color: Color(0xFFE5E5E5), + color: widget.hideLine ? Colors.transparent : Color(0xFFE5E5E5), ), ), ), child: MaterialButton( padding: EdgeInsets.zero, - onPressed: () { - Get.to(EventDetailPage()); - }, + onPressed: widget.canTap + ? () { + Get.to(EventDetailPage(themeId: widget.themeId)); + } + : null, child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -243,12 +306,12 @@ class _ChatCardState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - widget.name.text.size(36.sp).make(), + widget.name.text.black.size(36.sp).make(), 6.hb, - widget.content.text.make(), + widget.content.text.black.make(), 20.hb, _renderImage(), - widget.topic.isEmpty + widget.topic?.isEmpty ?? true ? SizedBox() : Chip( label: '#${widget.topic}'.text.size(22.sp).make(), @@ -262,6 +325,7 @@ class _ChatCardState extends State { ), Row( children: [ + 64.hb, BeeDateUtil(widget.date) .timeAgo .text @@ -309,6 +373,7 @@ class _ChatCardState extends State { _buildMoreButton(), ], ), + _renderLikeAndComment(), ], ).expand(), ],