From 4556db6f8f895559d3b89fb2e5f3c27de84339aa Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 4 Feb 2021 17:40:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8A=A8=E6=80=81=E5=8D=A1?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 5 + .../community_views/add_new_event_page.dart | 148 ++++++++++++++++++ .../community_views/community_page.dart | 4 +- .../community_views/new_community_view.dart | 5 +- .../topic/topic_detail_page.dart | 3 +- .../community_views/widgets/chat_card.dart | 24 ++- lib/widget/picker/bee_image_picker.dart | 1 + 7 files changed, 181 insertions(+), 9 deletions(-) create mode 100644 lib/ui/community/community_views/add_new_event_page.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 807db143..410233be 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -169,6 +169,9 @@ class _Community { String get eventByTopicId => '/user/gambit/listByGambitId'; String get newEventList => '/user/gambit/list'; + + ///社区活动: 写帖子(添加主题信息) + String get addEvent => '/user/gambit/writePost'; } class _Upload { @@ -180,4 +183,6 @@ class _Upload { ///上传报事报修信息 报事报修照片 String get uploadRepair => '/user/upload/uploadRepair'; + + String get uploadEvent => '/user/upload/uploadGambit'; } diff --git a/lib/ui/community/community_views/add_new_event_page.dart b/lib/ui/community/community_views/add_new_event_page.dart new file mode 100644 index 00000000..e45845d1 --- /dev/null +++ b/lib/ui/community/community_views/add_new_event_page.dart @@ -0,0 +1,148 @@ +import 'dart:io'; + +import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:akuCommunity/utils/network/base_model.dart'; +import 'package:akuCommunity/utils/network/net_util.dart'; +import 'package:akuCommunity/widget/picker/grid_image_picker.dart'; +import 'package:bot_toast/bot_toast.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class AddNewEventPage extends StatefulWidget { + AddNewEventPage({Key key}) : super(key: key); + + @override + _AddNewEventPageState createState() => _AddNewEventPageState(); +} + +class _AddNewEventPageState extends State { + bool _commentable = true; + List _files = []; + TextEditingController _textEditingController = TextEditingController(); + + ///发表动态 + _addEvent() async { + VoidCallback cancel = BotToast.showLoading(); + final String content = _textEditingController.text; + List imgs; + if (_files.isNotEmpty) { + imgs = await NetUtil().uploadFiles(_files, API.upload.uploadEvent); + } + + Map params = { + //TODO 话题ID + 'gambitId': -1, + 'content': content, + 'isComment': _commentable ? 1 : 0, + 'isPublic': 1, + 'imgUrls': imgs, + }; + + BaseModel baseModel = await NetUtil().post( + API.community.addEvent, + params: params, + showMessage: true, + ); + cancel(); + if (baseModel.status) { + Get.back(result: true); + } + } + + _buildSelectable() { + return MaterialButton( + onPressed: () { + setState(() { + _commentable = !_commentable; + }); + }, + height: 96.w, + child: Row( + children: [ + Icon( + CupertinoIcons.bubble_left, + size: 32.w, + ), + 8.wb, + '不可评论'.text.size(28.sp).make(), + Spacer(), + AnimatedOpacity( + opacity: _commentable ? 0 : 1, + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + child: Icon( + Icons.check_rounded, + color: Colors.black, + size: 40.w, + ), + ), + ], + ), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + backgroundColor: Colors.white, + elevation: 0, + leading: MaterialButton( + padding: EdgeInsets.zero, + onPressed: Get.back, + child: '取消'.text.size(34.sp).make(), + ), + leadingWidth: 108.w, + centerTitle: true, + title: '社区'.text.make(), + actions: [ + Hero( + tag: 'event_add', + child: MaterialButton( + elevation: 0, + minWidth: 116.w, + padding: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(4.w), + ), + color: kPrimaryColor, + onPressed: _addEvent, + child: '发表'.text.size(34.sp).make(), + ).centered(), + ), + 32.wb, + ], + ), + body: ListView( + padding: EdgeInsets.symmetric(horizontal: 64.w, vertical: 32.w), + children: [ + TextField( + minLines: 3, + maxLines: 99, + controller: _textEditingController, + decoration: InputDecoration( + contentPadding: EdgeInsets.zero, + border: InputBorder.none, + hintText: '这一刻的想法', + hintStyle: TextStyle( + color: Color(0xFF999999), + fontSize: 34.sp, + ), + ), + ), + GridImagePicker(onChange: (files) => _files = files), + 100.hb, + Divider(height: 1.w), + _buildSelectable(), + Divider(height: 1.w), + 28.hb, + //TODO 选择话题 + ], + ).material(color: Colors.white), + ); + } +} diff --git a/lib/ui/community/community_views/community_page.dart b/lib/ui/community/community_views/community_page.dart index 48cb5c31..b716ddfa 100644 --- a/lib/ui/community/community_views/community_page.dart +++ b/lib/ui/community/community_views/community_page.dart @@ -1,3 +1,4 @@ +import 'package:akuCommunity/ui/community/community_views/add_new_event_page.dart'; import 'package:akuCommunity/ui/community/community_views/my_community_view.dart'; import 'package:akuCommunity/ui/community/community_views/new_community_view.dart'; import 'package:akuCommunity/ui/community/community_views/topic/topic_community_view.dart'; @@ -6,6 +7,7 @@ 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:flutter/material.dart'; +import 'package:get/get.dart'; class CommunityPage extends StatefulWidget { CommunityPage({Key key}) : super(key: key); @@ -40,7 +42,7 @@ class _CommunityPageState extends State ), ], fab: FloatingActionButton( - onPressed: () {}, + onPressed: () => Get.to(AddNewEventPage()), heroTag: 'event_add', child: Icon(Icons.add), ), diff --git a/lib/ui/community/community_views/new_community_view.dart b/lib/ui/community/community_views/new_community_view.dart index 1b02a6ca..24ca4709 100644 --- a/lib/ui/community/community_views/new_community_view.dart +++ b/lib/ui/community/community_views/new_community_view.dart @@ -35,11 +35,12 @@ class _NewCommunityViewState extends State itemBuilder: (context, index) { final item = items[index] as EventItemModel; return ChatCard( + content: item.content, name: item.createName ?? '', - title: item.gambitTitle ?? '', + topic: item.gambitTitle ?? '', contentImg: item.imgUrls, date: item.date, - id: item.id, + id: item.createId, headImg: item.headSculptureImgUrl, ); }, 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 4405a778..4958529c 100644 --- a/lib/ui/community/community_views/topic/topic_detail_page.dart +++ b/lib/ui/community/community_views/topic/topic_detail_page.dart @@ -60,8 +60,9 @@ class _TopicDetailPageState extends State { (context, index) { final item = items[index] as EventItemModel; return ChatCard( + content: item.content, name: item.createName, - title: item.gambitTitle, + topic: item.gambitTitle, headImg: item.headSculptureImgUrl, contentImg: item.imgUrls, date: item.date, diff --git a/lib/ui/community/community_views/widgets/chat_card.dart b/lib/ui/community/community_views/widgets/chat_card.dart index e84de0aa..b3996497 100644 --- a/lib/ui/community/community_views/widgets/chat_card.dart +++ b/lib/ui/community/community_views/widgets/chat_card.dart @@ -15,23 +15,25 @@ import 'package:velocity_x/velocity_x.dart'; class ChatCard extends StatefulWidget { final String name; - final String title; + final String topic; final List headImg; final List contentImg; final DateTime date; final bool initLike; + final String content; ///userID final int id; ChatCard({ Key key, @required this.name, - @required this.title, + @required this.topic, @required this.headImg, @required this.contentImg, @required this.date, this.initLike = false, @required this.id, + @required this.content, }) : super(key: key); @override @@ -226,9 +228,21 @@ class _ChatCardState extends State { children: [ widget.name.text.size(36.sp).make(), 6.hb, - widget.title.text.make(), + widget.content.text.make(), 20.hb, _renderImage(), + widget.topic.isEmpty + ? SizedBox() + : Chip( + label: '#${widget.topic}'.text.size(22.sp).make(), + padding: EdgeInsets.symmetric( + horizontal: 16.w, vertical: 5.w), + labelPadding: EdgeInsets.zero, + backgroundColor: Colors.transparent, + shape: StadiumBorder( + side: BorderSide(), + ), + ), Row( children: [ BeeDateUtil(widget.date) @@ -248,13 +262,13 @@ class _ChatCardState extends State { title: '你确定删除吗'.text.isIntrinsic.make(), actions: [ CupertinoDialogAction( - child: '取消'.text.isIntrinsic.make(), + child: '取消'.text.black.isIntrinsic.make(), onPressed: () => Get.back(), ), CupertinoDialogAction( child: '确定' .text - .color(kPrimaryColor) + .color(Colors.orange) .isIntrinsic .make(), onPressed: () => Get.back(result: true), diff --git a/lib/widget/picker/bee_image_picker.dart b/lib/widget/picker/bee_image_picker.dart index 2b115a4e..3ba7a7b8 100644 --- a/lib/widget/picker/bee_image_picker.dart +++ b/lib/widget/picker/bee_image_picker.dart @@ -12,6 +12,7 @@ import 'package:velocity_x/velocity_x.dart'; // Project imports: import 'package:akuCommunity/utils/headers.dart'; +//TODO 图片大小限制 class BeeImagePicker { static Future pick({ String title,