2024-04-13 11:47:31 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:solian/models/post.dart';
|
|
|
|
import 'package:solian/widgets/posts/content/article.dart';
|
|
|
|
import 'package:solian/widgets/posts/content/attachment.dart';
|
|
|
|
import 'package:solian/widgets/posts/content/moment.dart';
|
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
|
|
|
|
|
|
|
class PostItem extends StatefulWidget {
|
|
|
|
final Post item;
|
2024-04-13 17:07:57 +00:00
|
|
|
final bool? brief;
|
2024-04-13 11:47:31 +00:00
|
|
|
|
2024-04-13 17:07:57 +00:00
|
|
|
const PostItem({super.key, required this.item, this.brief});
|
2024-04-13 11:47:31 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<PostItem> createState() => _PostItemState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostItemState extends State<PostItem> {
|
|
|
|
Map<String, dynamic>? reactionList;
|
|
|
|
|
|
|
|
Widget renderContent() {
|
|
|
|
switch (widget.item.modelType) {
|
2024-04-13 17:45:27 +00:00
|
|
|
case 'article':
|
2024-04-13 17:07:57 +00:00
|
|
|
return ArticleContent(item: widget.item, brief: widget.brief ?? true);
|
2024-04-13 11:47:31 +00:00
|
|
|
default:
|
2024-04-13 17:07:57 +00:00
|
|
|
return MomentContent(item: widget.item, brief: widget.brief ?? true);
|
2024-04-13 11:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget renderAttachments() {
|
2024-04-13 17:45:27 +00:00
|
|
|
if (widget.item.modelType == 'article') return Container();
|
|
|
|
|
|
|
|
if (widget.item.attachments != null &&
|
|
|
|
widget.item.attachments!.isNotEmpty) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
child: AttachmentList(items: widget.item.attachments!),
|
|
|
|
);
|
2024-04-13 11:47:31 +00:00
|
|
|
} else {
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-13 17:45:27 +00:00
|
|
|
String getAuthorDescribe() => widget.item.author.description.isNotEmpty
|
|
|
|
? widget.item.author.description
|
|
|
|
: 'No description yet.';
|
|
|
|
|
2024-04-13 11:47:31 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-04-13 17:45:27 +00:00
|
|
|
final headingParts = [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
widget.item.author.nick,
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
Text(timeago.format(widget.item.createdAt))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
if (widget.brief ?? true) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
CircleAvatar(
|
|
|
|
backgroundImage: NetworkImage(widget.item.author.avatar),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
...headingParts,
|
|
|
|
Padding(
|
2024-04-14 07:58:27 +00:00
|
|
|
padding: const EdgeInsets.only(left: 12, right: 12, top: 4),
|
2024-04-13 17:45:27 +00:00
|
|
|
child: renderContent(),
|
|
|
|
),
|
|
|
|
renderAttachments(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Column(
|
2024-04-13 11:47:31 +00:00
|
|
|
children: [
|
2024-04-13 17:45:27 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 12, right: 12, top: 16),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
CircleAvatar(
|
|
|
|
backgroundImage: NetworkImage(widget.item.author.avatar),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
...headingParts,
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
child: Text(
|
|
|
|
getAuthorDescribe(),
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
2024-04-13 11:47:31 +00:00
|
|
|
),
|
2024-04-13 17:45:27 +00:00
|
|
|
],
|
|
|
|
),
|
2024-04-13 11:47:31 +00:00
|
|
|
),
|
2024-04-13 17:45:27 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(top: 6),
|
|
|
|
child: Divider(thickness: 0.3),
|
2024-04-13 11:47:31 +00:00
|
|
|
),
|
|
|
|
Padding(
|
2024-04-13 17:45:27 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: renderContent(),
|
2024-04-13 11:47:31 +00:00
|
|
|
),
|
2024-04-13 17:45:27 +00:00
|
|
|
renderAttachments()
|
2024-04-13 11:47:31 +00:00
|
|
|
],
|
2024-04-13 17:45:27 +00:00
|
|
|
);
|
|
|
|
}
|
2024-04-13 11:47:31 +00:00
|
|
|
}
|
|
|
|
}
|