update chat card. working on chat detail page.

hmxc
小赖 4 years ago
parent 6dcba52485
commit c7f9ebfd13

@ -60,6 +60,7 @@ class _TopicDetailPageState extends State<TopicDetailPage> {
headImg: item.headSculptureImgUrl,
contentImg: item.imgUrls,
date: item.date,
id: item.createId,
);
},
childCount: items.length,

@ -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<ImgModel> headImg;
final List<ImgModel> 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<ChatCard> {
bool _like = false;
bool get _isMyself {
final userProvider = Provider.of<UserProvider>(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<ChatCard> {
);
}
_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<UserProvider>(context);
return DecoratedBox(
decoration: BoxDecoration(
color: Colors.white,
@ -60,12 +177,18 @@ class _ChatCardState extends State<ChatCard> {
),
),
),
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),
@ -85,13 +208,24 @@ class _ChatCardState extends State<ChatCard> {
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),
),
);
}
}

Loading…
Cancel
Save