parent
a87d6c9d69
commit
08afb5d1da
@ -0,0 +1,147 @@
|
|||||||
|
import 'package:akuCommunity/model/common/img_model.dart';
|
||||||
|
import 'package:common_utils/common_utils.dart';
|
||||||
|
|
||||||
|
class EventItemModel {
|
||||||
|
int id;
|
||||||
|
int createId;
|
||||||
|
int isComment;
|
||||||
|
int isLike;
|
||||||
|
String createName;
|
||||||
|
String content;
|
||||||
|
String gambitTitle;
|
||||||
|
String createDate;
|
||||||
|
List<LikeNames> likeNames;
|
||||||
|
List<ImgModel> imgUrls;
|
||||||
|
List<ImgModel> headSculptureImgUrl;
|
||||||
|
List<GambitThemeCommentVoList> gambitThemeCommentVoList;
|
||||||
|
DateTime get date => DateUtil.getDateTime(createDate);
|
||||||
|
EventItemModel(
|
||||||
|
{this.id,
|
||||||
|
this.createId,
|
||||||
|
this.isComment,
|
||||||
|
this.isLike,
|
||||||
|
this.createName,
|
||||||
|
this.content,
|
||||||
|
this.gambitTitle,
|
||||||
|
this.createDate,
|
||||||
|
this.likeNames,
|
||||||
|
this.imgUrls,
|
||||||
|
this.headSculptureImgUrl,
|
||||||
|
this.gambitThemeCommentVoList});
|
||||||
|
|
||||||
|
EventItemModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
createId = json['createId'];
|
||||||
|
isComment = json['isComment'];
|
||||||
|
isLike = json['isLike'];
|
||||||
|
createName = json['createName'];
|
||||||
|
content = json['content'];
|
||||||
|
gambitTitle = json['gambitTitle'];
|
||||||
|
createDate = json['createDate'];
|
||||||
|
if (json['likeNames'] != null) {
|
||||||
|
likeNames = new List<LikeNames>();
|
||||||
|
json['likeNames'].forEach((v) {
|
||||||
|
likeNames.add(new LikeNames.fromJson(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (json['imgUrls'] != null) {
|
||||||
|
imgUrls = new List<ImgModel>();
|
||||||
|
json['imgUrls'].forEach((v) {
|
||||||
|
imgUrls.add(new ImgModel.fromJson(v));
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
imgUrls = [];
|
||||||
|
if (json['headSculptureImgUrl'] != null) {
|
||||||
|
headSculptureImgUrl = new List<ImgModel>();
|
||||||
|
json['headSculptureImgUrl'].forEach((v) {
|
||||||
|
headSculptureImgUrl.add(new ImgModel.fromJson(v));
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
headSculptureImgUrl = [];
|
||||||
|
if (json['gambitThemeCommentVoList'] != null) {
|
||||||
|
gambitThemeCommentVoList = new List<GambitThemeCommentVoList>();
|
||||||
|
json['gambitThemeCommentVoList'].forEach((v) {
|
||||||
|
gambitThemeCommentVoList.add(new GambitThemeCommentVoList.fromJson(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||||
|
data['id'] = this.id;
|
||||||
|
data['createId'] = this.createId;
|
||||||
|
data['isComment'] = this.isComment;
|
||||||
|
data['isLike'] = this.isLike;
|
||||||
|
data['createName'] = this.createName;
|
||||||
|
data['content'] = this.content;
|
||||||
|
data['gambitTitle'] = this.gambitTitle;
|
||||||
|
data['createDate'] = this.createDate;
|
||||||
|
if (this.likeNames != null) {
|
||||||
|
data['likeNames'] = this.likeNames.map((v) => v.toJson()).toList();
|
||||||
|
}
|
||||||
|
if (this.imgUrls != null) {
|
||||||
|
data['imgUrls'] = this.imgUrls.map((v) => v.toJson()).toList();
|
||||||
|
}
|
||||||
|
if (this.headSculptureImgUrl != null) {
|
||||||
|
data['headSculptureImgUrl'] =
|
||||||
|
this.headSculptureImgUrl.map((v) => v.toJson()).toList();
|
||||||
|
}
|
||||||
|
if (this.gambitThemeCommentVoList != null) {
|
||||||
|
data['gambitThemeCommentVoList'] =
|
||||||
|
this.gambitThemeCommentVoList.map((v) => v.toJson()).toList();
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LikeNames {
|
||||||
|
int id;
|
||||||
|
String name;
|
||||||
|
|
||||||
|
LikeNames({this.id, this.name});
|
||||||
|
|
||||||
|
LikeNames.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
name = json['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||||
|
data['id'] = this.id;
|
||||||
|
data['name'] = this.name;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GambitThemeCommentVoList {
|
||||||
|
int id;
|
||||||
|
String parentName;
|
||||||
|
String content;
|
||||||
|
String createName;
|
||||||
|
String createDate;
|
||||||
|
|
||||||
|
GambitThemeCommentVoList(
|
||||||
|
{this.id,
|
||||||
|
this.parentName,
|
||||||
|
this.content,
|
||||||
|
this.createName,
|
||||||
|
this.createDate});
|
||||||
|
|
||||||
|
GambitThemeCommentVoList.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
parentName = json['parentName'];
|
||||||
|
content = json['content'];
|
||||||
|
createName = json['createName'];
|
||||||
|
createDate = json['createDate'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||||
|
data['id'] = this.id;
|
||||||
|
data['parentName'] = this.parentName;
|
||||||
|
data['content'] = this.content;
|
||||||
|
data['createName'] = this.createName;
|
||||||
|
data['createDate'] = this.createDate;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,97 @@
|
|||||||
|
import 'package:akuCommunity/constants/api.dart';
|
||||||
|
import 'package:akuCommunity/model/common/img_model.dart';
|
||||||
|
import 'package:akuCommunity/utils/bee_date_util.dart';
|
||||||
|
import 'package:akuCommunity/utils/headers.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:velocity_x/velocity_x.dart';
|
||||||
|
|
||||||
class ChatCard extends StatefulWidget {
|
class ChatCard extends StatefulWidget {
|
||||||
final String name;
|
final String name;
|
||||||
final String title;
|
final String title;
|
||||||
ChatCard({Key key, this.name, this.title}) : super(key: key);
|
final List<ImgModel> headImg;
|
||||||
|
final List<ImgModel> contentImg;
|
||||||
|
final DateTime date;
|
||||||
|
final bool canDelete;
|
||||||
|
ChatCard({
|
||||||
|
Key key,
|
||||||
|
this.name,
|
||||||
|
this.title,
|
||||||
|
this.headImg,
|
||||||
|
this.contentImg,
|
||||||
|
@required this.date,
|
||||||
|
this.canDelete,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ChatCardState createState() => _ChatCardState();
|
_ChatCardState createState() => _ChatCardState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ChatCardState extends State<ChatCard> {
|
class _ChatCardState extends State<ChatCard> {
|
||||||
|
String get firstHead {
|
||||||
|
if (widget.headImg == null || widget.headImg.isEmpty)
|
||||||
|
return '';
|
||||||
|
else
|
||||||
|
return widget.headImg.first.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
_renderImage() {
|
||||||
|
if (widget.contentImg.isEmpty) return SizedBox();
|
||||||
|
if (widget.contentImg.length == 1)
|
||||||
|
return ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
maxHeight: 300.w,
|
||||||
|
minWidth: 300.w,
|
||||||
|
),
|
||||||
|
child: FadeInImage.assetNetwork(
|
||||||
|
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
|
||||||
|
image: API.image(widget.contentImg.first.url),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container();
|
return DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
color: Color(0xFFE5E5E5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).expand(),
|
||||||
|
],
|
||||||
|
).p(20.w),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
import 'package:common_utils/common_utils.dart';
|
||||||
|
|
||||||
|
class BeeDateUtil {
|
||||||
|
DateTime date;
|
||||||
|
BeeDateUtil(this.date);
|
||||||
|
DateTime get _now => DateTime.now();
|
||||||
|
bool get sameYear => _now.year == this.date.year;
|
||||||
|
bool get sameMonth => sameYear && _now.month == this.date.month;
|
||||||
|
bool get sameDay => sameMonth && _now.day == this.date.day;
|
||||||
|
bool get isYesterday => (DateTime(_now.year, _now.month, _now.day - 1)
|
||||||
|
.compareTo(DateTime(this.date.year)) ==
|
||||||
|
0);
|
||||||
|
bool get isDoubleYesterday => (DateTime(_now.year, _now.month, _now.day - 2)
|
||||||
|
.compareTo(DateTime(this.date.year)) ==
|
||||||
|
0);
|
||||||
|
|
||||||
|
String get timeAgo {
|
||||||
|
Duration duration = _now.difference(date);
|
||||||
|
if (duration.inSeconds <= 60) return '${duration.inSeconds}秒前';
|
||||||
|
if (duration.inMinutes <= 60) return '${duration.inMinutes}分钟前';
|
||||||
|
if (duration.inHours <= 12) return '${duration.inHours}小时前';
|
||||||
|
if (isYesterday) return '昨天';
|
||||||
|
if (isDoubleYesterday) return '前天';
|
||||||
|
if (duration.inDays <= 30)
|
||||||
|
return '${duration.inDays}天前';
|
||||||
|
else
|
||||||
|
return DateUtil.formatDate(date, format: 'yyyy-MM-dd');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue