2024-05-25 05:19:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/exts.dart';
|
|
|
|
import 'package:solian/models/post.dart';
|
2024-07-23 10:09:41 +00:00
|
|
|
import 'package:solian/providers/content/posts.dart';
|
2024-09-16 17:23:49 +00:00
|
|
|
import 'package:solian/providers/last_read.dart';
|
2024-10-12 17:31:59 +00:00
|
|
|
import 'package:solian/theme.dart';
|
2024-10-13 13:31:15 +00:00
|
|
|
import 'package:solian/widgets/loading_indicator.dart';
|
2024-10-14 14:58:37 +00:00
|
|
|
import 'package:solian/widgets/posts/post_action.dart';
|
2024-05-25 05:19:16 +00:00
|
|
|
import 'package:solian/widgets/posts/post_item.dart';
|
2024-05-25 09:21:27 +00:00
|
|
|
import 'package:solian/widgets/posts/post_replies.dart';
|
2024-05-25 05:19:16 +00:00
|
|
|
|
|
|
|
class PostDetailScreen extends StatefulWidget {
|
2024-07-23 10:09:41 +00:00
|
|
|
final String id;
|
2024-08-01 20:42:38 +00:00
|
|
|
final Post? post;
|
2024-05-25 05:19:16 +00:00
|
|
|
|
2024-08-01 20:42:38 +00:00
|
|
|
const PostDetailScreen({
|
|
|
|
super.key,
|
|
|
|
required this.id,
|
|
|
|
this.post,
|
|
|
|
});
|
2024-05-25 05:19:16 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<PostDetailScreen> createState() => _PostDetailScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostDetailScreenState extends State<PostDetailScreen> {
|
2024-10-13 13:31:15 +00:00
|
|
|
bool _isBusy = true;
|
2024-05-25 05:19:16 +00:00
|
|
|
|
2024-10-13 13:31:15 +00:00
|
|
|
Post? _item;
|
2024-08-01 20:42:38 +00:00
|
|
|
|
2024-10-13 13:31:15 +00:00
|
|
|
Future<void> _getDetail() async {
|
|
|
|
final PostProvider posts = Get.find();
|
2024-05-25 05:19:16 +00:00
|
|
|
|
|
|
|
try {
|
2024-10-13 13:31:15 +00:00
|
|
|
final resp = await posts.getPost(widget.id);
|
|
|
|
_item = Post.fromJson(resp.body);
|
2024-05-25 05:19:16 +00:00
|
|
|
} catch (e) {
|
|
|
|
context.showErrorDialog(e).then((_) => Navigator.pop(context));
|
|
|
|
}
|
|
|
|
|
2024-10-13 13:31:15 +00:00
|
|
|
Get.find<LastReadProvider>().feedLastReadAt = _item?.id;
|
|
|
|
|
2024-10-14 14:58:37 +00:00
|
|
|
if (mounted) setState(() => _isBusy = false);
|
2024-10-13 13:31:15 +00:00
|
|
|
}
|
2024-09-16 17:23:49 +00:00
|
|
|
|
2024-10-13 13:31:15 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
if (widget.post != null) {
|
|
|
|
_item = widget.post;
|
|
|
|
}
|
|
|
|
_getDetail();
|
2024-05-25 05:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-10-13 13:31:15 +00:00
|
|
|
if (_isBusy && _item == null) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
2024-05-25 05:19:16 +00:00
|
|
|
|
2024-10-13 13:31:15 +00:00
|
|
|
return CustomScrollView(
|
|
|
|
slivers: [
|
2024-10-14 14:05:49 +00:00
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: LoadingIndicator(isActive: _isBusy),
|
|
|
|
),
|
2024-10-13 13:31:15 +00:00
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: PostItem(
|
2024-10-14 14:58:37 +00:00
|
|
|
key: ValueKey(_item),
|
2024-10-13 13:31:15 +00:00
|
|
|
item: _item!,
|
|
|
|
isClickable: false,
|
|
|
|
isOverrideEmbedClickable: true,
|
|
|
|
isFullDate: true,
|
|
|
|
isShowReply: false,
|
|
|
|
isContentSelectable: true,
|
|
|
|
padding: AppTheme.isLargeScreen(context)
|
|
|
|
? EdgeInsets.symmetric(
|
|
|
|
horizontal: 4,
|
|
|
|
vertical: 8,
|
|
|
|
)
|
|
|
|
: EdgeInsets.zero,
|
2024-10-14 14:58:37 +00:00
|
|
|
onTapMore: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => PostAction(
|
|
|
|
item: _item!,
|
|
|
|
noReact: true,
|
|
|
|
),
|
|
|
|
).then((value) {
|
|
|
|
if (value is Future) {
|
|
|
|
value.then((_) {
|
|
|
|
_getDetail();
|
|
|
|
});
|
|
|
|
} else if (value != null) {
|
|
|
|
_getDetail();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2024-10-13 13:31:15 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: const Divider(thickness: 0.3, height: 1).paddingOnly(
|
|
|
|
top: 8,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(
|
|
|
|
'postReplies'.tr,
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
).paddingOnly(left: 24, right: 24, top: 16),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
PostReplyList(
|
|
|
|
item: _item!,
|
|
|
|
padding: AppTheme.isLargeScreen(context)
|
|
|
|
? EdgeInsets.symmetric(
|
|
|
|
horizontal: 4,
|
|
|
|
vertical: 8,
|
|
|
|
)
|
|
|
|
: EdgeInsets.zero,
|
|
|
|
),
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: SizedBox(height: MediaQuery.of(context).padding.bottom),
|
|
|
|
),
|
|
|
|
],
|
2024-05-25 05:19:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|