From 11f9ce371a84a12e5758febc84d6fc73a474fd72 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 16:01:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=8D=A1=E7=89=87=E6=B7=BB?= =?UTF-8?q?=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(), ],