diff --git a/lib/constants/api.dart b/lib/constants/api.dart index e84fca38..a5812abe 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -199,6 +199,9 @@ class _Community { ///社区话题:查询主题信息详情 String get getEventDetail => '/user/gambit/GambitThemeDetail'; + + ///社区话题:评论 + String get sendAComment => '/user/gambit/comment'; } class _Upload { diff --git a/lib/ui/community/community_views/widgets/chat_card.dart b/lib/ui/community/community_views/widgets/chat_card.dart index eb4eb583..d732024d 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/ui/community/community_views/widgets/send_a_chat.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -147,7 +148,12 @@ class _ChatCardState extends State { height: 78.w, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - onPressed: () {}, + onPressed: () { + SendAChat.send( + parentId: 0, + themeId: widget.model.id, + ); + }, child: [ Icon(CupertinoIcons.bubble_right, size: 30.w), 10.wb, @@ -217,40 +223,13 @@ class _ChatCardState extends State { return InkWell( child: buffer.toString().text.make(), onTap: () { - addComment(); + SendAChat.send(parentId: e.id, themeId: widget.model.id); }, ); }).toList(), ); } - addComment() async { - FocusNode node = FocusNode(); - node.requestFocus(); - Get.bottomSheet( - Row( - children: [ - TextField( - focusNode: node, - decoration: InputDecoration( - border: OutlineInputBorder(), - isDense: true, - ), - ).p(16.w).expand(), - 16.wb, - MaterialButton( - color: kPrimaryColor, - onPressed: () {}, - minWidth: 64.w, - child: '发送'.text.make(), - ), - 16.wb, - ], - ).material(color: Colors.white), - barrierColor: Colors.transparent, - ); - } - _renderLikeAndComment() { return Material( borderRadius: BorderRadius.circular(8.w), diff --git a/lib/ui/community/community_views/widgets/send_a_chat.dart b/lib/ui/community/community_views/widgets/send_a_chat.dart new file mode 100644 index 00000000..ef3926ff --- /dev/null +++ b/lib/ui/community/community_views/widgets/send_a_chat.dart @@ -0,0 +1,75 @@ +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/utils/network/net_util.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class SendAChat extends StatefulWidget { + final FocusNode node; + SendAChat({Key key, this.node}) : super(key: key); + + static Future send({ + @required int parentId, + @required int themeId, + }) async { + FocusNode node = FocusNode(); + node.requestFocus(); + String result = await Get.bottomSheet( + SendAChat(node: node), + barrierColor: Colors.transparent, + ); + if (result != null) { + await NetUtil().post( + API.community.sendAComment, + params: { + 'parentId': parentId, + 'gambitThemeId': themeId, + 'content': result, + }, + showMessage: true, + ); + return true; + } + return false; + } + + @override + _SendAChatState createState() => _SendAChatState(); +} + +class _SendAChatState extends State { + TextEditingController _textEditingController = TextEditingController(); + @override + void dispose() { + _textEditingController?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Row( + children: [ + TextField( + focusNode: widget.node, + controller: _textEditingController, + decoration: InputDecoration( + border: OutlineInputBorder(), + isDense: true, + ), + ).p(16.w).expand(), + 16.wb, + MaterialButton( + color: kPrimaryColor, + onPressed: () { + Get.back(result: _textEditingController.text); + }, + minWidth: 64.w, + child: '发送'.text.make(), + ), + 16.wb, + ], + ).material(color: Colors.white); + } +}