2022-07-03 13:47:24 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-07-04 17:37:53 +00:00
|
|
|
import 'package:localization/localization.dart';
|
2022-08-06 14:50:30 +00:00
|
|
|
import 'package:loris/business_logic/account/account.dart';
|
|
|
|
import 'package:loris/business_logic/timeline/media.dart';
|
|
|
|
import 'package:loris/partials/media_attachment.dart';
|
2022-08-06 18:15:16 +00:00
|
|
|
import 'package:loris/partials/post_options.dart';
|
2022-08-06 16:46:31 +00:00
|
|
|
import 'package:loris/partials/post_text_renderer.dart';
|
2022-08-01 08:29:43 +00:00
|
|
|
import '../business_logic/timeline/timeline.dart' as tl;
|
2022-07-03 13:47:24 +00:00
|
|
|
|
|
|
|
class Post extends StatefulWidget {
|
2022-08-01 08:29:43 +00:00
|
|
|
const Post({required this.model, Key? key}) : super(key: key);
|
|
|
|
final tl.PostModel model;
|
2022-07-03 13:47:24 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<Post> createState() => _PostState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostState extends State<Post> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
2022-08-06 16:46:31 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2022-07-03 13:47:24 +00:00
|
|
|
children: [
|
2022-08-06 11:47:18 +00:00
|
|
|
DisplayName(account: widget.model.account),
|
2022-08-01 08:29:43 +00:00
|
|
|
PostBody(
|
2022-08-01 08:59:30 +00:00
|
|
|
sensitive: widget.model.sensitive,
|
2022-08-01 08:29:43 +00:00
|
|
|
content: widget.model.content,
|
2022-08-01 08:59:30 +00:00
|
|
|
spoilerText: widget.model.spoilerText,
|
2022-08-06 14:05:14 +00:00
|
|
|
media: widget.model.attachments,
|
2022-08-01 08:29:43 +00:00
|
|
|
),
|
2022-08-06 20:13:12 +00:00
|
|
|
postActionBar(context, widget.model),
|
2022-08-07 17:01:59 +00:00
|
|
|
RebloggedBy(account: widget.model.rebloggedBy),
|
2022-07-03 14:56:41 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DisplayName extends StatelessWidget {
|
|
|
|
const DisplayName({
|
2022-08-06 11:47:18 +00:00
|
|
|
required this.account,
|
2022-07-03 14:56:41 +00:00
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
2022-08-06 11:47:18 +00:00
|
|
|
final AccountModel account;
|
2022-07-03 14:56:41 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
children: [
|
2022-08-06 11:47:18 +00:00
|
|
|
ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: ProfilePic(
|
|
|
|
url: account.avatar,
|
|
|
|
)),
|
|
|
|
const SizedBox(width: 8),
|
2022-08-06 14:50:30 +00:00
|
|
|
Flexible(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
account.displayName,
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
account.acct,
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-07-03 13:47:24 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-07 17:01:59 +00:00
|
|
|
class RebloggedBy extends StatelessWidget {
|
|
|
|
const RebloggedBy({
|
|
|
|
required this.account,
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
final AccountModel? account;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (account != null) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.repeat),
|
|
|
|
Flexible(child: SelectableText("reblogged-by".i18n())),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
DisplayName(account: account!),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-06 11:47:18 +00:00
|
|
|
class ProfilePic extends StatelessWidget {
|
|
|
|
const ProfilePic({required this.url, Key? key}) : super(key: key);
|
|
|
|
final String url;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
const double width = 64;
|
|
|
|
if (url.isNotEmpty) {
|
|
|
|
return Image.network(
|
|
|
|
url,
|
2022-08-10 18:49:51 +00:00
|
|
|
errorBuilder: (context, error, stackTrace) => const Icon(
|
|
|
|
Icons.cruelty_free,
|
|
|
|
size: width,
|
|
|
|
),
|
2022-08-06 14:50:30 +00:00
|
|
|
height: width,
|
|
|
|
width: width,
|
2022-08-06 11:47:18 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Icon(
|
|
|
|
Icons.cruelty_free,
|
|
|
|
size: width,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-03 20:02:57 +00:00
|
|
|
class PostBody extends StatefulWidget {
|
2022-08-01 08:59:30 +00:00
|
|
|
const PostBody({
|
|
|
|
required this.sensitive,
|
|
|
|
required this.spoilerText,
|
|
|
|
required this.content,
|
2022-08-06 14:05:14 +00:00
|
|
|
required this.media,
|
2022-08-01 08:59:30 +00:00
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
2022-08-01 08:29:43 +00:00
|
|
|
final String content;
|
2022-08-01 08:59:30 +00:00
|
|
|
final String spoilerText;
|
|
|
|
final bool sensitive;
|
2022-08-06 14:05:14 +00:00
|
|
|
final List<MediaAttachmentModel> media;
|
2022-07-03 20:02:57 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<PostBody> createState() => _PostBodyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostBodyState extends State<PostBody> {
|
|
|
|
bool visible = false;
|
2022-07-04 17:37:53 +00:00
|
|
|
String cwButtonText = "show".i18n();
|
|
|
|
Icon cwButtonIcon = const Icon(Icons.visibility);
|
2022-07-03 20:02:57 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-01 08:59:30 +00:00
|
|
|
if (!widget.sensitive) {
|
|
|
|
visible = true;
|
|
|
|
}
|
2022-07-03 20:02:57 +00:00
|
|
|
return Container(
|
|
|
|
width: double.infinity,
|
|
|
|
padding: const EdgeInsets.fromLTRB(0, 6, 0, 6),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-08-01 08:59:30 +00:00
|
|
|
Visibility(
|
|
|
|
visible: widget.sensitive,
|
|
|
|
child: Text(widget.spoilerText),
|
|
|
|
),
|
|
|
|
Visibility(
|
|
|
|
visible: widget.sensitive,
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
visible = !visible;
|
|
|
|
if (visible) {
|
|
|
|
cwButtonIcon = const Icon(Icons.visibility_off);
|
|
|
|
cwButtonText = "hide".i18n();
|
|
|
|
} else {
|
|
|
|
cwButtonText = "show".i18n();
|
|
|
|
cwButtonIcon = const Icon(Icons.visibility);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: cwButtonIcon,
|
|
|
|
label: Text(cwButtonText)),
|
|
|
|
),
|
2022-07-03 20:02:57 +00:00
|
|
|
Visibility(
|
|
|
|
visible: visible,
|
2022-08-06 14:05:14 +00:00
|
|
|
child: Column(
|
2022-08-06 16:46:31 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2022-08-06 14:05:14 +00:00
|
|
|
children: [
|
2022-08-06 16:56:33 +00:00
|
|
|
PostTextRenderer(htmlInput: widget.content),
|
2022-08-06 14:05:14 +00:00
|
|
|
MediaAttachments(models: widget.media),
|
|
|
|
],
|
2022-07-03 20:02:57 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2022-07-03 13:47:24 +00:00
|
|
|
),
|
2022-07-03 20:02:57 +00:00
|
|
|
);
|
|
|
|
}
|
2022-07-03 13:47:24 +00:00
|
|
|
}
|
|
|
|
|
2022-08-06 20:13:12 +00:00
|
|
|
Widget postActionBar(context, tl.PostModel model) {
|
2022-07-03 13:47:24 +00:00
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {},
|
|
|
|
icon: const Icon(Icons.reply),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {},
|
|
|
|
icon: const Icon(Icons.repeat),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {},
|
|
|
|
icon: const Icon(Icons.favorite_outline),
|
|
|
|
),
|
|
|
|
IconButton(
|
2022-08-06 18:15:16 +00:00
|
|
|
onPressed: () {
|
2022-08-06 20:13:12 +00:00
|
|
|
popupPostOptions(context, model);
|
2022-08-06 18:15:16 +00:00
|
|
|
},
|
2022-07-03 13:47:24 +00:00
|
|
|
icon: const Icon(Icons.more_horiz),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|