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, headImg: item.headSculptureImgUrl,
contentImg: item.imgUrls, contentImg: item.imgUrls,
date: item.date, date: item.date,
id: item.createId,
); );
}, },
childCount: items.length, childCount: items.length,

@ -1,8 +1,12 @@
import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/model/common/img_model.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/bee_date_util.dart';
import 'package:akuCommunity/utils/headers.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:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
class ChatCard extends StatefulWidget { class ChatCard extends StatefulWidget {
@ -11,7 +15,10 @@ class ChatCard extends StatefulWidget {
final List<ImgModel> headImg; final List<ImgModel> headImg;
final List<ImgModel> contentImg; final List<ImgModel> contentImg;
final DateTime date; final DateTime date;
final bool canDelete; final bool initLike;
///userID
final int id;
ChatCard({ ChatCard({
Key key, Key key,
this.name, this.name,
@ -19,7 +26,8 @@ class ChatCard extends StatefulWidget {
this.headImg, this.headImg,
this.contentImg, this.contentImg,
@required this.date, @required this.date,
this.canDelete, this.initLike = false,
@required this.id,
}) : super(key: key); }) : super(key: key);
@override @override
@ -27,6 +35,13 @@ class ChatCard extends StatefulWidget {
} }
class _ChatCardState extends State<ChatCard> { 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 { String get firstHead {
if (widget.headImg == null || widget.headImg.isEmpty) if (widget.headImg == null || widget.headImg.isEmpty)
return ''; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final userProvider = Provider.of<UserProvider>(context);
return DecoratedBox( return DecoratedBox(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, 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( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Material( Material(
color: Color(0xFFF5F5F5), color: Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(6.w), borderRadius: BorderRadius.circular(6.w),
clipBehavior: Clip.antiAlias,
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(firstHead), image: API.image(firstHead),
@ -85,13 +208,24 @@ class _ChatCardState extends State<ChatCard> {
Row( Row(
children: [ children: [
BeeDateUtil(widget.date).timeAgo.text.make(), BeeDateUtil(widget.date).timeAgo.text.make(),
_isMyself
? FlatButton(
materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap,
height: 48.w,
onPressed: () {},
child: '删除'.text.black.size(28.sp).make(),
)
: SizedBox(),
Spacer(), Spacer(),
_buildMoreButton(),
], ],
), ),
], ],
).expand(), ).expand(),
], ],
).p(20.w), ).p(20.w),
),
); );
} }
} }

Loading…
Cancel
Save