From 863c87033445253de19c305fdad0f8eaa3888b19 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 5 Feb 2021 10:17:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=88=91=E7=9A=84=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 3 + lib/model/community/my_event_item_model.dart | 43 ++++++++ lib/pages/property/property_index.dart | 1 + .../community_views/my_community_view.dart | 29 ++++- .../widgets/my_event_card.dart | 103 ++++++++++++++++++ 5 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 lib/model/community/my_event_item_model.dart create mode 100644 lib/ui/community/community_views/widgets/my_event_card.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 6c5d4581..00bb41ed 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -178,6 +178,9 @@ class _Community { ///社区话题:查询活跃话题(取前4个) String get hotTopic => '/user/gambit/findActivityGambit'; + + ///社区话题:我的动态 + String get myEvent => '/user/gambit/myTidings'; } class _Upload { diff --git a/lib/model/community/my_event_item_model.dart b/lib/model/community/my_event_item_model.dart new file mode 100644 index 00000000..4728c54a --- /dev/null +++ b/lib/model/community/my_event_item_model.dart @@ -0,0 +1,43 @@ +import 'package:akuCommunity/model/common/img_model.dart'; +import 'package:flustars/flustars.dart'; + +class MyEventItemModel { + int id; + String content; + List imgUrl; + String createDate; + + String get firstImg { + String img = ''; + if (imgUrl.isNotEmpty) img = imgUrl.first.url; + return img; + } + + DateTime get date => DateUtil.getDateTime(createDate); + + MyEventItemModel({this.id, this.content, this.imgUrl, this.createDate}); + + MyEventItemModel.fromJson(Map json) { + id = json['id']; + content = json['content']; + if (json['imgUrl'] != null) { + imgUrl = new List(); + json['imgUrl'].forEach((v) { + imgUrl.add(new ImgModel.fromJson(v)); + }); + } else + imgUrl = []; + createDate = json['createDate']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['content'] = this.content; + if (this.imgUrl != null) { + data['imgUrl'] = this.imgUrl.map((v) => v.toJson()).toList(); + } + data['createDate'] = this.createDate; + return data; + } +} diff --git a/lib/pages/property/property_index.dart b/lib/pages/property/property_index.dart index c010eb3a..29dc85b1 100644 --- a/lib/pages/property/property_index.dart +++ b/lib/pages/property/property_index.dart @@ -60,6 +60,7 @@ class _PropertyIndexState extends State controller: _refreshController, firstRefresh: true, header: MaterialHeader(), + footer: MaterialFooter(), onRefresh: () async { _page = 1; _models = await _getItems(); diff --git a/lib/ui/community/community_views/my_community_view.dart b/lib/ui/community/community_views/my_community_view.dart index 3a101b32..3a6016a3 100644 --- a/lib/ui/community/community_views/my_community_view.dart +++ b/lib/ui/community/community_views/my_community_view.dart @@ -1,4 +1,10 @@ +import 'package:akuCommunity/ui/community/community_views/widgets/my_event_card.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/community/my_event_item_model.dart'; +import 'package:akuCommunity/pages/things_page/widget/bee_list_view.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; class MyCommunityView extends StatefulWidget { MyCommunityView({Key key}) : super(key: key); @@ -9,10 +15,31 @@ class MyCommunityView extends StatefulWidget { class _MyCommunityViewState extends State with AutomaticKeepAliveClientMixin { + EasyRefreshController _refreshController = EasyRefreshController(); @override Widget build(BuildContext context) { super.build(context); - return Container(); + return BeeListView( + path: API.community.myEvent, + controller: _refreshController, + convert: (model) { + return model.tableList + .map((e) => MyEventItemModel.fromJson(e)) + .toList(); + }, + builder: (items) { + return ListView.separated( + itemBuilder: (context, index) { + final MyEventItemModel model = items[index]; + MyEventItemModel preModel; + if (index >= 1) preModel = items[index - 1]; + return MyEventCard(model: model, preModel: preModel); + }, + separatorBuilder: (_, __) => 8.hb, + itemCount: items.length, + ); + }, + ); } @override diff --git a/lib/ui/community/community_views/widgets/my_event_card.dart b/lib/ui/community/community_views/widgets/my_event_card.dart new file mode 100644 index 00000000..085baef1 --- /dev/null +++ b/lib/ui/community/community_views/widgets/my_event_card.dart @@ -0,0 +1,103 @@ +import 'package:akuCommunity/const/resource.dart'; +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/community/my_event_item_model.dart'; +import 'package:akuCommunity/ui/community/notice/notice_detail_page.dart'; +import 'package:akuCommunity/utils/bee_date_util.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:akuCommunity/model/community/board_model.dart'; +import 'package:akuCommunity/widget/picker/bee_image_preview.dart'; +import 'package:flustars/flustars.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class MyEventCard extends StatelessWidget { + final MyEventItemModel model; + final MyEventItemModel preModel; + const MyEventCard({ + Key key, + @required this.model, + @required this.preModel, + }) : super(key: key); + + bool get isFirst => preModel == null; + + bool get notSameYear => model.date.year != (preModel?.date?.year ?? 0); + + BeeDateUtil get beeDate => BeeDateUtil(model.date); + + Widget title() { + if (beeDate.sameDay) return '今天'.text.size(52.sp).bold.make(); + if (beeDate.isYesterday) + return '昨天'.text.size(52.sp).bold.make(); + else + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + model.date.day.toString().text.size(52.sp).bold.make(), + '${model.date.month}月'.text.size(36.sp).make(), + ], + ); + } + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + (notSameYear && model.date.year != DateTime.now().year) + ? '${model.date.year}年' + .text + .bold + .size(52.sp) + .make() + .paddingOnly(left: 32.w, top: isFirst ? 0 : 64.w, bottom: 32.w) + : SizedBox(), + MaterialButton( + onPressed: () {}, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 200.w, + padding: EdgeInsets.only(left: 32.w), + alignment: Alignment.topLeft, + child: beeDate.sameDay ? SizedBox() : title(), + ), + model.imgUrl.length == 0 + ? SizedBox(height: 152.w) + : GestureDetector( + onTap: () { + Get.to( + BeeImagePreview.path(path: model.imgUrl.first.url), + opaque: false, + ); + }, + child: Hero( + tag: model.imgUrl.first.url, + child: Container( + clipBehavior: Clip.antiAlias, + decoration: BoxDecoration( + color: Colors.black12, + borderRadius: BorderRadius.circular(8.w), + ), + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: API.image(model.imgUrl.first.url), + width: 152.w, + height: 152.w, + fit: BoxFit.cover, + ), + ), + ), + ), + 10.wb, + model.content.text.make().expand(), + ], + ), + ), + ], + ); + } +}