修复点赞问题

pull/1/head
张萌 3 years ago
parent 6550a40a4a
commit 3a73097ea8

@ -48,6 +48,7 @@ class _ChatCardState extends State<ChatCard> {
} }
late bool _isLiked; late bool _isLiked;
late int _likeNum;
_renderImage() { _renderImage() {
if (widget.model.dynamicList.isEmpty) return SizedBox(); if (widget.model.dynamicList.isEmpty) return SizedBox();
@ -106,6 +107,13 @@ class _ChatCardState extends State<ChatCard> {
params: {'dynamicId': widget.model.id}); params: {'dynamicId': widget.model.id});
if (res.success) { if (res.success) {
_isLiked = !_isLiked; _isLiked = !_isLiked;
if (_isLiked) {
_likeNum += 1;
} else {
_likeNum -= 1;
}
BotToast.showText(text: _isLiked ? '点赞成功' : '取消点赞成功');
setState(() {}); setState(() {});
} else { } else {
BotToast.showText(text: res.msg); BotToast.showText(text: res.msg);
@ -162,6 +170,7 @@ class _ChatCardState extends State<ChatCard> {
@override @override
void initState() { void initState() {
_isLiked = widget.model.isLike; _isLiked = widget.model.isLike;
_likeNum = widget.model.likes;
super.initState(); super.initState();
} }
@ -273,7 +282,7 @@ class _ChatCardState extends State<ChatCard> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
32.hb, 32.hb,
if(!widget.model.content!.isEmptyOrNull) if (!widget.model.content!.isEmptyOrNull)
widget.model.content!.text.size(32.sp).black.make(), widget.model.content!.text.size(32.sp).black.make(),
32.hb, 32.hb,
_renderImage(), _renderImage(),

@ -7,8 +7,10 @@ import 'package:aku_new_community/provider/user_provider.dart';
import 'package:aku_new_community/ui/community/community_views/add_new_event_page.dart'; import 'package:aku_new_community/ui/community/community_views/add_new_event_page.dart';
import 'package:aku_new_community/utils/bee_date_util.dart'; import 'package:aku_new_community/utils/bee_date_util.dart';
import 'package:aku_new_community/utils/headers.dart'; import 'package:aku_new_community/utils/headers.dart';
import 'package:aku_new_community/utils/network/net_util.dart';
import 'package:aku_new_community/widget/picker/bee_image_preview.dart'; import 'package:aku_new_community/widget/picker/bee_image_preview.dart';
import 'package:aku_new_community/widget/views/bee_grid_image_view.dart'; import 'package:aku_new_community/widget/views/bee_grid_image_view.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart'; import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -43,6 +45,16 @@ class _ChatCardDetailState extends State<ChatCardDetail> {
return (userProvider.userInfoModel?.id ?? -1) == widget.model.createId; return (userProvider.userInfoModel?.id ?? -1) == widget.model.createId;
} }
late bool _isLiked;
late int _likeNum;
@override
void initState() {
_isLiked = widget.model.isLike;
_likeNum = widget.model.likes;
super.initState();
}
_renderImage() { _renderImage() {
if (widget.model.dynamicImgList.isEmpty) return SizedBox(); if (widget.model.dynamicImgList.isEmpty) return SizedBox();
if (widget.model.dynamicImgList.length == 1) if (widget.model.dynamicImgList.length == 1)
@ -140,11 +152,32 @@ class _ChatCardDetailState extends State<ChatCardDetail> {
Spacer(), Spacer(),
LikeButton( LikeButton(
size: 40.w, size: 40.w,
likeBuilder: (bool isLiked){ isLiked: _isLiked,
onTap: (isLiked) async {
var res = await NetUtil().get(SAASAPI.community.dynamicLike,
params: {'dynamicId': widget.model.id});
if (res.success) {
_isLiked = !_isLiked;
if (_isLiked) {
_likeNum += 1;
} else {
_likeNum -= 1;
}
BotToast.showText(text: _isLiked ? '点赞成功' : '取消点赞成功');
setState(() {});
} else {
BotToast.showText(text: res.msg);
}
},
likeBuilder: (bool isLiked) {
return Image.asset( return Image.asset(
isLiked ? Assets.icons.communityLikeIs.path : Assets.icons.communityLike.path,); isLiked
? Assets.icons.communityLikeIs.path
: Assets.icons.communityLike.path,
);
}, },
likeCount:widget.model.likes, likeCount: _likeNum,
), ),
// Image.asset( // Image.asset(
// Assets.icons.communityLikeIs.path, // Assets.icons.communityLikeIs.path,
@ -166,11 +199,11 @@ class _ChatCardDetailState extends State<ChatCardDetail> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
32.hb, 32.hb,
if(!widget.model.content!.isEmptyOrNull) if (!widget.model.content!.isEmptyOrNull)
widget.model.content!.text widget.model.content!.text
.size(28.sp) .size(28.sp)
.color(ktextSubColor) .color(ktextSubColor)
.make(), .make(),
32.hb, 32.hb,
_renderImage(), _renderImage(),
20.hb, 20.hb,
@ -201,32 +234,31 @@ class _ChatCardDetailState extends State<ChatCardDetail> {
]).paddingOnly(bottom: 16.w); ]).paddingOnly(bottom: 16.w);
} }
// _renderLikeAndComment() {
// _renderLikeAndComment() { // if (widget.model!.likeNames!.isEmpty &&
// if (widget.model!.likeNames!.isEmpty && // widget.model!.gambitThemeCommentVoList!.isEmpty) return SizedBox();
// widget.model!.gambitThemeCommentVoList!.isEmpty) return SizedBox(); // return Material(
// return Material( // borderRadius: BorderRadius.circular(8.w),
// borderRadius: BorderRadius.circular(8.w), // color: Color(0xFFF7F7F7),
// color: Color(0xFFF7F7F7), // child: Padding(
// child: Padding( // padding: EdgeInsets.all(8.w),
// padding: EdgeInsets.all(8.w), // child: Column(
// child: Column( // crossAxisAlignment: CrossAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.start, // children: [
// children: [ // widget.model!.likeNames!.isEmpty ? SizedBox() : _renderLike(),
// widget.model!.likeNames!.isEmpty ? SizedBox() : _renderLike(), // 10.hb,
// 10.hb, // (widget.model!.likeNames!.isNotEmpty &&
// (widget.model!.likeNames!.isNotEmpty && // widget.model!.gambitThemeCommentVoList!.isNotEmpty)
// widget.model!.gambitThemeCommentVoList!.isNotEmpty) // ? Divider(height: 1.w, thickness: 1.w)
// ? Divider(height: 1.w, thickness: 1.w) // : SizedBox(),
// : SizedBox(), // 10.hb,
// 10.hb, // widget.model!.gambitThemeCommentVoList!.isEmpty
// widget.model!.gambitThemeCommentVoList!.isEmpty // ? SizedBox()
// ? SizedBox() // : _renderComment(),
// : _renderComment(), // ],
// ], // ),
// ), // ),
// ), // );
// ); // }
// }
} }

Loading…
Cancel
Save