2024-08-01 20:42:38 +00:00
|
|
|
import 'package:animations/animations.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-08-04 09:35:58 +00:00
|
|
|
import 'package:flutter/rendering.dart';
|
2024-09-16 15:39:15 +00:00
|
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
2024-05-23 12:00:26 +00:00
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
2024-09-07 09:45:44 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2024-09-16 15:35:44 +00:00
|
|
|
import 'package:get/get.dart';
|
2024-06-22 17:52:05 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
import 'package:solian/models/post.dart';
|
2024-09-16 15:35:44 +00:00
|
|
|
import 'package:solian/providers/content/posts.dart';
|
2024-08-01 20:42:38 +00:00
|
|
|
import 'package:solian/screens/posts/post_detail.dart';
|
|
|
|
import 'package:solian/shells/title_shell.dart';
|
2024-09-13 12:22:10 +00:00
|
|
|
import 'package:solian/theme.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
import 'package:solian/widgets/account/account_avatar.dart';
|
2024-06-02 06:42:07 +00:00
|
|
|
import 'package:solian/widgets/account/account_profile_popup.dart';
|
2024-05-18 14:23:36 +00:00
|
|
|
import 'package:solian/widgets/attachments/attachment_list.dart';
|
2024-08-19 11:56:44 +00:00
|
|
|
import 'package:solian/widgets/link_expansion.dart';
|
2024-07-11 16:44:57 +00:00
|
|
|
import 'package:solian/widgets/markdown_text_content.dart';
|
2024-07-31 18:10:57 +00:00
|
|
|
import 'package:solian/widgets/posts/post_tags.dart';
|
2024-05-21 16:05:03 +00:00
|
|
|
import 'package:solian/widgets/posts/post_quick_action.dart';
|
2024-07-26 06:21:00 +00:00
|
|
|
import 'package:solian/widgets/sized_container.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
import 'package:timeago/timeago.dart' show format;
|
|
|
|
|
|
|
|
class PostItem extends StatefulWidget {
|
|
|
|
final Post item;
|
2024-05-25 05:19:16 +00:00
|
|
|
final bool isClickable;
|
2024-05-22 12:56:10 +00:00
|
|
|
final bool isCompact;
|
2024-05-21 16:05:03 +00:00
|
|
|
final bool isReactable;
|
2024-05-25 05:19:16 +00:00
|
|
|
final bool isShowReply;
|
2024-05-25 09:21:27 +00:00
|
|
|
final bool isShowEmbed;
|
2024-08-04 13:12:35 +00:00
|
|
|
final bool isOverrideEmbedClickable;
|
2024-06-22 17:52:05 +00:00
|
|
|
final bool isFullDate;
|
2024-08-04 09:35:58 +00:00
|
|
|
final bool isFullContent;
|
2024-07-13 10:54:08 +00:00
|
|
|
final bool isContentSelectable;
|
2024-09-16 15:35:44 +00:00
|
|
|
final bool showFeaturedReply;
|
2024-08-01 21:10:10 +00:00
|
|
|
final String? attachmentParent;
|
|
|
|
final Color? backgroundColor;
|
2024-05-18 10:17:16 +00:00
|
|
|
|
2024-05-21 16:05:03 +00:00
|
|
|
const PostItem({
|
|
|
|
super.key,
|
|
|
|
required this.item,
|
2024-05-25 05:19:16 +00:00
|
|
|
this.isClickable = false,
|
2024-05-22 12:56:10 +00:00
|
|
|
this.isCompact = false,
|
2024-05-21 16:05:03 +00:00
|
|
|
this.isReactable = true,
|
2024-05-25 05:19:16 +00:00
|
|
|
this.isShowReply = true,
|
2024-05-25 09:21:27 +00:00
|
|
|
this.isShowEmbed = true,
|
2024-08-04 13:12:35 +00:00
|
|
|
this.isOverrideEmbedClickable = false,
|
2024-06-22 17:52:05 +00:00
|
|
|
this.isFullDate = false,
|
2024-08-04 09:35:58 +00:00
|
|
|
this.isFullContent = false,
|
2024-07-13 10:54:08 +00:00
|
|
|
this.isContentSelectable = false,
|
2024-09-16 15:35:44 +00:00
|
|
|
this.showFeaturedReply = false,
|
2024-08-01 21:10:10 +00:00
|
|
|
this.attachmentParent,
|
|
|
|
this.backgroundColor,
|
2024-05-21 16:05:03 +00:00
|
|
|
});
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<PostItem> createState() => _PostItemState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostItemState extends State<PostItem> {
|
2024-05-19 12:30:50 +00:00
|
|
|
late final Post item;
|
|
|
|
|
2024-07-13 10:54:08 +00:00
|
|
|
Color get _unFocusColor =>
|
|
|
|
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
|
|
|
|
|
2024-05-19 12:30:50 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
item = widget.item;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2024-07-25 17:16:32 +00:00
|
|
|
Widget _buildDate() {
|
2024-06-22 17:52:05 +00:00
|
|
|
if (widget.isFullDate) {
|
2024-07-30 06:49:26 +00:00
|
|
|
return Text(DateFormat('y/M/d HH:mm')
|
2024-07-25 17:16:32 +00:00
|
|
|
.format(item.publishedAt?.toLocal() ?? DateTime.now()));
|
2024-06-22 17:52:05 +00:00
|
|
|
} else {
|
2024-07-25 17:16:32 +00:00
|
|
|
return Text(
|
|
|
|
format(
|
|
|
|
item.publishedAt?.toLocal() ?? DateTime.now(),
|
|
|
|
locale: 'en_short',
|
|
|
|
),
|
|
|
|
);
|
2024-06-22 17:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-10 17:57:58 +00:00
|
|
|
Widget _buildThumbnail() {
|
2024-09-07 09:48:07 +00:00
|
|
|
if (widget.item.body['thumbnail'] == null) return const SizedBox.shrink();
|
2024-08-17 10:44:20 +00:00
|
|
|
final border = BorderSide(
|
|
|
|
color: Theme.of(context).dividerColor,
|
|
|
|
width: 0.3,
|
|
|
|
);
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(border: Border(top: border, bottom: border)),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 16 / 9,
|
|
|
|
child: AttachmentSelfContainedEntry(
|
2024-08-18 14:51:52 +00:00
|
|
|
rid: widget.item.body['thumbnail'],
|
2024-08-17 10:44:20 +00:00
|
|
|
parentId: 'p${item.id}-thumbnail',
|
2024-08-10 17:57:58 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-25 17:16:32 +00:00
|
|
|
Widget _buildHeader() {
|
2024-06-22 17:52:05 +00:00
|
|
|
return Row(
|
2024-08-04 12:48:51 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-06-22 17:52:05 +00:00
|
|
|
children: [
|
2024-06-26 16:33:49 +00:00
|
|
|
if (widget.isCompact)
|
|
|
|
AccountAvatar(
|
2024-09-16 15:35:44 +00:00
|
|
|
content: item.author.avatar,
|
2024-06-26 16:33:49 +00:00
|
|
|
radius: 10,
|
2024-08-04 12:48:51 +00:00
|
|
|
).paddingOnly(left: 2, top: 1),
|
2024-07-30 06:49:26 +00:00
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
item.author.nick,
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
_buildDate().paddingOnly(left: 4),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (item.body['title'] != null)
|
|
|
|
Text(
|
|
|
|
item.body['title'],
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyMedium!
|
|
|
|
.copyWith(fontSize: 15),
|
|
|
|
),
|
|
|
|
if (item.body['description'] != null)
|
|
|
|
Text(
|
|
|
|
item.body['description'],
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).paddingOnly(left: widget.isCompact ? 6 : 12),
|
|
|
|
),
|
2024-08-04 12:48:51 +00:00
|
|
|
if (widget.item.type == 'article')
|
|
|
|
Badge(
|
|
|
|
label: Text('article'.tr),
|
|
|
|
).paddingOnly(top: 3),
|
2024-06-22 17:52:05 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-04 12:48:51 +00:00
|
|
|
Widget _buildHeaderDivider() {
|
|
|
|
if (item.body['description'] != null || item.body['title'] != null) {
|
|
|
|
return const Divider(thickness: 0.3, height: 1).paddingSymmetric(
|
|
|
|
vertical: 8,
|
|
|
|
);
|
|
|
|
}
|
2024-09-07 09:48:07 +00:00
|
|
|
return const SizedBox.shrink();
|
2024-08-04 12:48:51 +00:00
|
|
|
}
|
|
|
|
|
2024-07-25 17:16:32 +00:00
|
|
|
Widget _buildFooter() {
|
2024-06-22 17:52:05 +00:00
|
|
|
List<String> labels = List.empty(growable: true);
|
2024-07-30 06:49:26 +00:00
|
|
|
if (widget.item.editedAt != null) {
|
2024-06-22 17:52:05 +00:00
|
|
|
labels.add('postEdited'.trParams({
|
2024-07-30 06:49:26 +00:00
|
|
|
'date': DateFormat('yy/M/d HH:mm').format(item.editedAt!.toLocal()),
|
2024-06-22 17:52:05 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
if (widget.item.realm != null) {
|
|
|
|
labels.add('postInRealm'.trParams({
|
2024-07-25 06:42:50 +00:00
|
|
|
'realm': widget.item.realm!.alias,
|
2024-06-22 17:52:05 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2024-07-08 11:56:03 +00:00
|
|
|
List<Widget> widgets = List.empty(growable: true);
|
|
|
|
|
|
|
|
if (widget.item.tags?.isNotEmpty ?? false) {
|
2024-07-31 18:10:57 +00:00
|
|
|
widgets.add(PostTagsList(tags: widget.item.tags!));
|
2024-07-08 11:56:03 +00:00
|
|
|
}
|
2024-06-22 17:52:05 +00:00
|
|
|
if (labels.isNotEmpty) {
|
2024-07-08 11:56:03 +00:00
|
|
|
widgets.add(Text(
|
2024-06-23 10:51:49 +00:00
|
|
|
labels.join(' · '),
|
2024-06-22 17:52:05 +00:00
|
|
|
textAlign: TextAlign.left,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
2024-07-13 10:54:08 +00:00
|
|
|
color: _unFocusColor,
|
2024-06-22 17:52:05 +00:00
|
|
|
),
|
2024-07-08 11:56:03 +00:00
|
|
|
));
|
|
|
|
}
|
2024-07-26 10:23:51 +00:00
|
|
|
if (widget.item.pinnedAt != null) {
|
|
|
|
widgets.add(Text(
|
|
|
|
'postPinned'.tr,
|
|
|
|
style: TextStyle(fontSize: 12, color: _unFocusColor),
|
|
|
|
));
|
|
|
|
}
|
2024-07-08 11:56:03 +00:00
|
|
|
|
|
|
|
if (widgets.isEmpty) {
|
2024-09-07 09:48:07 +00:00
|
|
|
return const SizedBox.shrink();
|
2024-07-08 11:56:03 +00:00
|
|
|
} else {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: widgets,
|
2024-07-09 13:23:38 +00:00
|
|
|
).paddingOnly(top: 4);
|
2024-06-22 17:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-25 17:16:32 +00:00
|
|
|
Widget _buildReply(BuildContext context) {
|
2024-08-01 20:42:38 +00:00
|
|
|
return OpenContainer(
|
2024-08-04 13:12:35 +00:00
|
|
|
tappable: widget.isClickable || widget.isOverrideEmbedClickable,
|
2024-08-01 20:42:38 +00:00
|
|
|
closedBuilder: (_, openContainer) => Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
FaIcon(
|
|
|
|
FontAwesomeIcons.reply,
|
|
|
|
size: 16,
|
|
|
|
color: _unFocusColor,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
'postRepliedNotify'.trParams(
|
|
|
|
{'username': '@${widget.item.replyTo!.author.name}'},
|
|
|
|
),
|
|
|
|
style: TextStyle(color: _unFocusColor),
|
|
|
|
).paddingOnly(left: 6),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).paddingOnly(left: 12),
|
|
|
|
Card(
|
|
|
|
elevation: 1,
|
|
|
|
child: PostItem(
|
|
|
|
item: widget.item.replyTo!,
|
|
|
|
isCompact: true,
|
2024-08-01 21:10:10 +00:00
|
|
|
attachmentParent: widget.item.id.toString(),
|
2024-08-01 20:42:38 +00:00
|
|
|
).paddingSymmetric(vertical: 8),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
openBuilder: (_, __) => TitleShell(
|
|
|
|
title: 'postDetail'.tr,
|
|
|
|
child: PostDetailScreen(
|
|
|
|
id: widget.item.replyTo!.id.toString(),
|
|
|
|
post: widget.item.replyTo!,
|
2024-05-22 12:56:10 +00:00
|
|
|
),
|
2024-08-01 20:42:38 +00:00
|
|
|
),
|
2024-08-01 21:10:10 +00:00
|
|
|
closedElevation: 0,
|
|
|
|
openElevation: 0,
|
2024-08-04 09:15:56 +00:00
|
|
|
closedColor:
|
|
|
|
widget.backgroundColor ?? Theme.of(context).colorScheme.surface,
|
2024-08-01 20:42:38 +00:00
|
|
|
openColor: Theme.of(context).colorScheme.surface,
|
2024-05-22 12:56:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-25 17:16:32 +00:00
|
|
|
Widget _buildRepost(BuildContext context) {
|
2024-08-01 20:42:38 +00:00
|
|
|
return OpenContainer(
|
2024-08-04 13:12:35 +00:00
|
|
|
tappable: widget.isClickable || widget.isOverrideEmbedClickable,
|
2024-08-01 20:42:38 +00:00
|
|
|
closedBuilder: (_, openContainer) => Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
FaIcon(
|
|
|
|
FontAwesomeIcons.retweet,
|
|
|
|
size: 16,
|
|
|
|
color: _unFocusColor,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
'postRepostedNotify'.trParams(
|
|
|
|
{'username': '@${widget.item.repostTo!.author.name}'},
|
|
|
|
),
|
|
|
|
style: TextStyle(color: _unFocusColor),
|
|
|
|
).paddingOnly(left: 6),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).paddingOnly(left: 12),
|
|
|
|
Card(
|
|
|
|
elevation: 1,
|
|
|
|
child: PostItem(
|
|
|
|
item: widget.item.repostTo!,
|
|
|
|
isCompact: true,
|
2024-08-01 21:10:10 +00:00
|
|
|
attachmentParent: widget.item.id.toString(),
|
2024-08-01 20:42:38 +00:00
|
|
|
).paddingSymmetric(vertical: 8),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
openBuilder: (_, __) => TitleShell(
|
|
|
|
title: 'postDetail'.tr,
|
|
|
|
child: PostDetailScreen(
|
|
|
|
id: widget.item.repostTo!.id.toString(),
|
|
|
|
post: widget.item.repostTo!,
|
2024-05-22 12:56:10 +00:00
|
|
|
),
|
2024-08-01 20:42:38 +00:00
|
|
|
),
|
2024-08-01 21:10:10 +00:00
|
|
|
closedElevation: 0,
|
|
|
|
openElevation: 0,
|
2024-08-04 09:15:56 +00:00
|
|
|
closedColor:
|
|
|
|
widget.backgroundColor ?? Theme.of(context).colorScheme.surface,
|
2024-08-01 20:42:38 +00:00
|
|
|
openColor: Theme.of(context).colorScheme.surface,
|
2024-05-22 12:56:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-19 14:13:25 +00:00
|
|
|
Widget _buildAttachments() {
|
|
|
|
final List<String> attachments = item.body['attachments'] is List
|
|
|
|
? List.from(item.body['attachments']?.whereType<String>())
|
|
|
|
: List.empty();
|
|
|
|
|
|
|
|
if (attachments.length > 3) {
|
|
|
|
return AttachmentList(
|
|
|
|
parentId: widget.item.id.toString(),
|
|
|
|
attachmentsId: attachments,
|
2024-09-10 13:36:10 +00:00
|
|
|
autoload: false,
|
2024-08-19 14:13:25 +00:00
|
|
|
isGrid: true,
|
|
|
|
).paddingOnly(left: 36, top: 4, bottom: 4);
|
2024-09-13 12:22:10 +00:00
|
|
|
} else if (attachments.length > 1 || AppTheme.isLargeScreen(context)) {
|
2024-08-19 14:13:25 +00:00
|
|
|
return AttachmentList(
|
|
|
|
parentId: widget.item.id.toString(),
|
|
|
|
attachmentsId: attachments,
|
2024-09-10 13:36:10 +00:00
|
|
|
autoload: false,
|
2024-08-19 14:13:25 +00:00
|
|
|
isColumn: true,
|
|
|
|
).paddingOnly(left: 60, right: 24);
|
|
|
|
} else {
|
|
|
|
return AttachmentList(
|
|
|
|
flatMaxHeight: MediaQuery.of(context).size.width,
|
|
|
|
parentId: widget.item.id.toString(),
|
|
|
|
attachmentsId: attachments,
|
2024-09-10 13:36:10 +00:00
|
|
|
autoload: false,
|
2024-08-19 14:13:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-16 15:35:44 +00:00
|
|
|
Widget _buildFeaturedReply() {
|
|
|
|
if ((widget.item.metric?.replyCount ?? 0) == 0) {
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
}
|
|
|
|
final List<String> attachments = item.body['attachments'] is List
|
|
|
|
? List.from(item.body['attachments']?.whereType<String>())
|
|
|
|
: List.empty();
|
|
|
|
final unFocusColor =
|
|
|
|
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
|
|
|
|
return FutureBuilder(
|
|
|
|
future: Get.find<PostProvider>().listPostFeaturedReply(
|
|
|
|
widget.item.id.toString(),
|
|
|
|
),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
}
|
|
|
|
return Card(
|
|
|
|
margin: EdgeInsets.zero,
|
|
|
|
child: Column(
|
|
|
|
children: snapshot.data!
|
|
|
|
.map(
|
|
|
|
(x) => Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
AccountAvatar(content: x.author.avatar, radius: 10),
|
|
|
|
const Gap(6),
|
|
|
|
Text(
|
|
|
|
x.author.nick,
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
const Gap(6),
|
|
|
|
Text(
|
|
|
|
format(
|
|
|
|
x.publishedAt?.toLocal() ?? DateTime.now(),
|
|
|
|
locale: 'en_short',
|
|
|
|
),
|
|
|
|
).paddingOnly(top: 0.5),
|
2024-09-16 15:39:15 +00:00
|
|
|
const Gap(8),
|
2024-09-16 15:35:44 +00:00
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
MarkdownTextContent(
|
|
|
|
content: x.body['content'],
|
|
|
|
parentId: 'p${item.id}-featured-reply${x.id}',
|
|
|
|
),
|
|
|
|
if (x.body['attachments'] is List &&
|
|
|
|
x.body['attachments'].length > 0)
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.file_copy,
|
|
|
|
size: 15,
|
|
|
|
color: unFocusColor,
|
|
|
|
).paddingOnly(right: 5),
|
|
|
|
Text(
|
|
|
|
'attachmentHint'.trParams(
|
|
|
|
{
|
|
|
|
'count': x.body['attachments'].length
|
|
|
|
.toString()
|
|
|
|
},
|
|
|
|
),
|
|
|
|
style: TextStyle(color: unFocusColor),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).paddingSymmetric(horizontal: 12, vertical: 8),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
),
|
2024-09-16 15:39:15 +00:00
|
|
|
)
|
|
|
|
.animate()
|
|
|
|
.fadeIn(
|
|
|
|
duration: 300.ms,
|
|
|
|
curve: Curves.easeIn,
|
|
|
|
)
|
|
|
|
.paddingOnly(
|
|
|
|
top: (attachments.length == 1 && !AppTheme.isLargeScreen(context))
|
|
|
|
? 10
|
|
|
|
: 6,
|
|
|
|
left:
|
|
|
|
(attachments.length == 1 && !AppTheme.isLargeScreen(context))
|
|
|
|
? 24
|
|
|
|
: 60,
|
|
|
|
right: 16,
|
|
|
|
);
|
2024-09-16 15:35:44 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-04 09:35:58 +00:00
|
|
|
double _contentHeight = 0;
|
|
|
|
|
2024-05-18 10:17:16 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-08-18 14:51:52 +00:00
|
|
|
final List<String> attachments = item.body['attachments'] is List
|
2024-08-19 01:19:29 +00:00
|
|
|
? List.from(item.body['attachments']?.whereType<String>())
|
2024-07-25 08:08:46 +00:00
|
|
|
: List.empty();
|
|
|
|
final hasAttachment = attachments.isNotEmpty;
|
2024-05-19 12:30:50 +00:00
|
|
|
|
2024-05-22 12:56:10 +00:00
|
|
|
if (widget.isCompact) {
|
|
|
|
return Column(
|
2024-06-22 17:52:05 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-05-22 12:56:10 +00:00
|
|
|
children: [
|
2024-08-18 17:54:32 +00:00
|
|
|
_buildThumbnail().paddingOnly(bottom: 8),
|
2024-07-25 17:16:32 +00:00
|
|
|
_buildHeader().paddingSymmetric(horizontal: 12),
|
2024-08-04 12:48:51 +00:00
|
|
|
_buildHeaderDivider().paddingSymmetric(horizontal: 12),
|
2024-08-04 12:43:25 +00:00
|
|
|
Stack(
|
|
|
|
children: [
|
|
|
|
SizedContainer(
|
|
|
|
maxWidth: 640,
|
|
|
|
maxHeight: widget.isFullContent ? double.infinity : 80,
|
|
|
|
child: _MeasureSize(
|
|
|
|
onChange: (size) {
|
|
|
|
setState(() => _contentHeight = size.height);
|
|
|
|
},
|
|
|
|
child: MarkdownTextContent(
|
2024-08-06 08:24:47 +00:00
|
|
|
parentId: 'p${item.id}',
|
2024-08-04 12:43:25 +00:00
|
|
|
content: item.body['content'],
|
|
|
|
isSelectable: widget.isContentSelectable,
|
|
|
|
).paddingOnly(
|
|
|
|
left: 16,
|
|
|
|
right: 12,
|
|
|
|
top: 2,
|
|
|
|
bottom: hasAttachment ? 4 : 0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (_contentHeight >= 80 && !widget.isFullContent)
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: IgnorePointer(
|
|
|
|
child: Container(
|
|
|
|
height: 80,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: LinearGradient(
|
|
|
|
begin: Alignment.bottomCenter,
|
|
|
|
end: Alignment.topCenter,
|
|
|
|
colors: [
|
|
|
|
Theme.of(context).colorScheme.surfaceContainerLow,
|
2024-09-11 11:56:32 +00:00
|
|
|
Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.surface
|
|
|
|
.withOpacity(0),
|
2024-08-04 12:43:25 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-05-22 12:56:10 +00:00
|
|
|
),
|
2024-08-19 11:56:44 +00:00
|
|
|
LinkExpansion(content: item.body['content']).paddingOnly(
|
|
|
|
left: 8,
|
|
|
|
right: 8,
|
|
|
|
top: 4,
|
|
|
|
),
|
2024-07-25 17:16:32 +00:00
|
|
|
_buildFooter().paddingOnly(left: 16),
|
2024-07-25 08:08:46 +00:00
|
|
|
if (attachments.isNotEmpty)
|
2024-07-13 10:54:08 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
2024-08-06 12:00:13 +00:00
|
|
|
Icons.file_copy,
|
|
|
|
size: 15,
|
2024-07-13 10:54:08 +00:00
|
|
|
color: _unFocusColor,
|
2024-08-06 12:00:13 +00:00
|
|
|
).paddingOnly(right: 5),
|
2024-07-13 10:54:08 +00:00
|
|
|
Text(
|
2024-08-01 08:28:48 +00:00
|
|
|
'attachmentHint'.trParams(
|
2024-07-25 08:08:46 +00:00
|
|
|
{'count': attachments.length.toString()},
|
2024-07-13 10:54:08 +00:00
|
|
|
),
|
|
|
|
style: TextStyle(color: _unFocusColor),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
).paddingOnly(left: 16, top: 4),
|
2024-05-22 12:56:10 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-01 20:42:38 +00:00
|
|
|
return OpenContainer(
|
2024-08-04 09:15:56 +00:00
|
|
|
tappable: widget.isClickable,
|
2024-08-01 20:42:38 +00:00
|
|
|
closedBuilder: (_, openContainer) => Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-08-17 10:44:20 +00:00
|
|
|
_buildThumbnail().paddingOnly(bottom: 4),
|
2024-08-01 20:42:38 +00:00
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
GestureDetector(
|
2024-09-16 15:35:44 +00:00
|
|
|
child: AccountAvatar(content: item.author.avatar),
|
2024-08-01 20:42:38 +00:00
|
|
|
onTap: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
isScrollControlled: true,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AccountProfilePopup(
|
2024-08-03 04:29:13 +00:00
|
|
|
name: item.author.name,
|
2024-05-25 05:19:16 +00:00
|
|
|
),
|
2024-08-01 20:42:38 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
_buildHeader(),
|
2024-08-04 12:48:51 +00:00
|
|
|
_buildHeaderDivider(),
|
2024-08-04 12:43:25 +00:00
|
|
|
Stack(
|
|
|
|
children: [
|
|
|
|
SizedContainer(
|
|
|
|
maxWidth: 640,
|
|
|
|
maxHeight:
|
|
|
|
widget.isFullContent ? double.infinity : 320,
|
|
|
|
child: _MeasureSize(
|
|
|
|
onChange: (size) {
|
|
|
|
setState(() => _contentHeight = size.height);
|
|
|
|
},
|
|
|
|
child: MarkdownTextContent(
|
2024-08-10 17:57:58 +00:00
|
|
|
parentId: 'p${item.id}-embed',
|
2024-08-04 12:43:25 +00:00
|
|
|
content: item.body['content'],
|
|
|
|
isSelectable: widget.isContentSelectable,
|
2024-09-17 13:48:20 +00:00
|
|
|
isLargeText: item.type == 'article' &&
|
|
|
|
widget.isFullContent,
|
2024-08-04 12:43:25 +00:00
|
|
|
).paddingOnly(left: 12, right: 8),
|
2024-08-04 09:35:58 +00:00
|
|
|
),
|
|
|
|
),
|
2024-08-04 12:43:25 +00:00
|
|
|
if (_contentHeight >= 320 && !widget.isFullContent)
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: IgnorePointer(
|
|
|
|
child: Container(
|
|
|
|
height: 320,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: LinearGradient(
|
|
|
|
begin: Alignment.bottomCenter,
|
|
|
|
end: Alignment.topCenter,
|
|
|
|
colors: [
|
|
|
|
Theme.of(context).colorScheme.surface,
|
2024-09-11 11:56:32 +00:00
|
|
|
Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.surface
|
|
|
|
.withOpacity(0),
|
2024-08-04 12:43:25 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-08-01 20:42:38 +00:00
|
|
|
if (widget.item.replyTo != null && widget.isShowEmbed)
|
2024-08-19 12:13:08 +00:00
|
|
|
Container(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 480),
|
|
|
|
padding: const EdgeInsets.only(top: 4),
|
|
|
|
child: _buildReply(context),
|
|
|
|
),
|
2024-08-01 20:42:38 +00:00
|
|
|
if (widget.item.repostTo != null && widget.isShowEmbed)
|
2024-08-19 12:13:08 +00:00
|
|
|
Container(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 480),
|
|
|
|
padding: const EdgeInsets.only(top: 4),
|
|
|
|
child: _buildRepost(context),
|
|
|
|
),
|
2024-08-01 20:42:38 +00:00
|
|
|
_buildFooter().paddingOnly(left: 12),
|
2024-08-19 11:56:44 +00:00
|
|
|
LinkExpansion(content: item.body['content'])
|
|
|
|
.paddingOnly(top: 4),
|
2024-08-01 20:42:38 +00:00
|
|
|
],
|
|
|
|
),
|
2024-05-18 10:17:16 +00:00
|
|
|
),
|
2024-08-01 20:42:38 +00:00
|
|
|
],
|
2024-07-09 15:06:55 +00:00
|
|
|
).paddingOnly(
|
2024-08-01 20:42:38 +00:00
|
|
|
top: 10,
|
2024-09-13 12:22:10 +00:00
|
|
|
bottom:
|
|
|
|
(attachments.length == 1 && !AppTheme.isLargeScreen(context))
|
|
|
|
? 10
|
|
|
|
: 0,
|
2024-07-09 15:06:55 +00:00
|
|
|
right: 16,
|
2024-08-01 20:42:38 +00:00
|
|
|
left: 16,
|
|
|
|
),
|
2024-08-19 14:13:25 +00:00
|
|
|
_buildAttachments(),
|
2024-09-16 15:35:44 +00:00
|
|
|
if (widget.showFeaturedReply) _buildFeaturedReply(),
|
2024-08-06 12:00:13 +00:00
|
|
|
if (widget.isShowReply || widget.isReactable)
|
2024-08-01 20:42:38 +00:00
|
|
|
PostQuickAction(
|
|
|
|
isShowReply: widget.isShowReply,
|
|
|
|
isReactable: widget.isReactable,
|
|
|
|
item: widget.item,
|
|
|
|
onReact: (symbol, changes) {
|
|
|
|
setState(() {
|
|
|
|
item.metric!.reactionList[symbol] =
|
|
|
|
(item.metric!.reactionList[symbol] ?? 0) + changes;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
).paddingOnly(
|
2024-09-13 12:22:10 +00:00
|
|
|
top: (attachments.length == 1 && !AppTheme.isLargeScreen(context))
|
|
|
|
? 10
|
|
|
|
: 6,
|
|
|
|
left:
|
|
|
|
(attachments.length == 1 && !AppTheme.isLargeScreen(context))
|
|
|
|
? 24
|
|
|
|
: 60,
|
2024-08-01 20:42:38 +00:00
|
|
|
right: 16,
|
|
|
|
bottom: 10,
|
|
|
|
)
|
|
|
|
else
|
2024-09-07 09:45:44 +00:00
|
|
|
const Gap(10),
|
2024-08-01 20:42:38 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
openBuilder: (_, __) => TitleShell(
|
|
|
|
title: 'postDetail'.tr,
|
|
|
|
child: PostDetailScreen(
|
|
|
|
id: item.id.toString(),
|
|
|
|
post: item,
|
|
|
|
),
|
|
|
|
),
|
2024-08-01 21:10:10 +00:00
|
|
|
closedElevation: 0,
|
|
|
|
openElevation: 0,
|
2024-08-04 09:15:56 +00:00
|
|
|
closedColor:
|
|
|
|
widget.backgroundColor ?? Theme.of(context).colorScheme.surface,
|
2024-08-01 20:42:38 +00:00
|
|
|
openColor: Theme.of(context).colorScheme.surface,
|
2024-05-18 10:17:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-08-04 09:35:58 +00:00
|
|
|
|
|
|
|
typedef _OnWidgetSizeChange = void Function(Size size);
|
|
|
|
|
|
|
|
class _MeasureSizeRenderObject extends RenderProxyBox {
|
|
|
|
Size? oldSize;
|
|
|
|
_OnWidgetSizeChange onChange;
|
|
|
|
|
|
|
|
_MeasureSizeRenderObject(this.onChange);
|
|
|
|
|
|
|
|
@override
|
|
|
|
void performLayout() {
|
|
|
|
super.performLayout();
|
|
|
|
|
|
|
|
Size newSize = child!.size;
|
|
|
|
if (oldSize == newSize) return;
|
|
|
|
|
|
|
|
oldSize = newSize;
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
onChange(newSize);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MeasureSize extends SingleChildRenderObjectWidget {
|
|
|
|
final _OnWidgetSizeChange onChange;
|
|
|
|
|
|
|
|
const _MeasureSize({
|
|
|
|
required this.onChange,
|
|
|
|
required Widget super.child,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
RenderObject createRenderObject(BuildContext context) {
|
|
|
|
return _MeasureSizeRenderObject(onChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void updateRenderObject(
|
|
|
|
BuildContext context, covariant _MeasureSizeRenderObject renderObject) {
|
|
|
|
renderObject.onChange = onChange;
|
|
|
|
}
|
|
|
|
}
|