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 704d41a6..ac748c49 100644 --- a/lib/ui/community/community_views/topic/topic_detail_page.dart +++ b/lib/ui/community/community_views/topic/topic_detail_page.dart @@ -60,6 +60,7 @@ class _TopicDetailPageState extends State { headImg: item.headSculptureImgUrl, contentImg: item.imgUrls, date: item.date, + id: item.createId, ); }, 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 4d0e6fbd..974c836c 100644 --- a/lib/ui/community/community_views/widgets/chat_card.dart +++ b/lib/ui/community/community_views/widgets/chat_card.dart @@ -1,8 +1,12 @@ import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/model/common/img_model.dart'; +import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/bee_date_util.dart'; import 'package:akuCommunity/utils/headers.dart'; +import 'package:bot_toast/bot_toast.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; class ChatCard extends StatefulWidget { @@ -11,7 +15,10 @@ class ChatCard extends StatefulWidget { final List headImg; final List contentImg; final DateTime date; - final bool canDelete; + final bool initLike; + + ///userID + final int id; ChatCard({ Key key, this.name, @@ -19,7 +26,8 @@ class ChatCard extends StatefulWidget { this.headImg, this.contentImg, @required this.date, - this.canDelete, + this.initLike = false, + @required this.id, }) : super(key: key); @override @@ -27,6 +35,13 @@ class ChatCard extends StatefulWidget { } class _ChatCardState extends State { + bool _like = false; + + bool get _isMyself { + final userProvider = Provider.of(context, listen: false); + return (userProvider?.userInfoModel?.id ?? -1) == widget.id; + } + String get firstHead { if (widget.headImg == null || widget.headImg.isEmpty) return ''; @@ -49,8 +64,110 @@ class _ChatCardState extends State { ); } + _buildMoreButton() { + return Builder(builder: (context) { + return MaterialButton( + elevation: 0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(6.w), + ), + padding: EdgeInsets.zero, + height: 40.w, + minWidth: 0, + color: Color(0xFFD8D8D8), + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + onPressed: () { + BotToast.showAttachedWidget( + targetContext: context, + preferDirection: PreferDirection.leftCenter, + attachedBuilder: (cancel) { + return Padding( + padding: EdgeInsets.only(right: 10.w), + child: Material( + color: Color(0xFFD8D8D8), + borderRadius: BorderRadius.circular(8.w), + clipBehavior: Clip.antiAlias, + child: SizedBox( + height: 78.w, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + MaterialButton( + height: 78.w, + materialTapTargetSize: + MaterialTapTargetSize.shrinkWrap, + onPressed: () { + cancel(); + //TODO 点赞 + setState(() { + _like = !_like; + }); + }, + child: [ + _like + ? Icon(Icons.favorite, + size: 30.w, color: Colors.red) + : Icon(Icons.favorite_border, size: 30.w), + 10.wb, + '赞'.text.make(), + ].row(), + ), + VerticalDivider(width: 1.w, thickness: 1.w), + MaterialButton( + height: 78.w, + materialTapTargetSize: + MaterialTapTargetSize.shrinkWrap, + onPressed: () {}, + child: [ + Icon(CupertinoIcons.bubble_right, size: 30.w), + 10.wb, + '评论'.text.make(), + ].row(), + ), + ], + ), + ), + ), + ); + }, + ); + }, + child: Row( + children: [ + 20.wb, + Container( + height: 8.w, + width: 8.w, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(4.w), + ), + ), + 8.wb, + Container( + height: 8.w, + width: 8.w, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(4.w), + ), + ), + 20.wb, + ], + ), + ); + }); + } + + @override + void initState() { + super.initState(); + _like = widget.initLike ?? false; + } + @override Widget build(BuildContext context) { + final userProvider = Provider.of(context); return DecoratedBox( decoration: BoxDecoration( color: Colors.white, @@ -60,38 +177,55 @@ class _ChatCardState extends State { ), ), ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Material( - color: Color(0xFFF5F5F5), - borderRadius: BorderRadius.circular(6.w), - child: FadeInImage.assetNetwork( - placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, - image: API.image(firstHead), - height: 86.w, - width: 86.w, - ), - ), - 24.wb, - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - widget.name.text.size(36.sp).make(), - 6.hb, - widget.title.text.make(), - 20.hb, - _renderImage(), - Row( - children: [ - BeeDateUtil(widget.date).timeAgo.text.make(), - Spacer(), - ], + child: MaterialButton( + padding: EdgeInsets.zero, + onPressed: () { + //TODO go to chat detail page. + }, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Material( + color: Color(0xFFF5F5F5), + borderRadius: BorderRadius.circular(6.w), + clipBehavior: Clip.antiAlias, + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: API.image(firstHead), + height: 86.w, + width: 86.w, ), - ], - ).expand(), - ], - ).p(20.w), + ), + 24.wb, + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + widget.name.text.size(36.sp).make(), + 6.hb, + widget.title.text.make(), + 20.hb, + _renderImage(), + Row( + children: [ + BeeDateUtil(widget.date).timeAgo.text.make(), + _isMyself + ? FlatButton( + materialTapTargetSize: + MaterialTapTargetSize.shrinkWrap, + height: 48.w, + onPressed: () {}, + child: '删除'.text.black.size(28.sp).make(), + ) + : SizedBox(), + Spacer(), + _buildMoreButton(), + ], + ), + ], + ).expand(), + ], + ).p(20.w), + ), ); } }