import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:solian/exts.dart'; import 'package:solian/models/post.dart'; import 'package:solian/providers/content/posts.dart'; import 'package:solian/providers/last_read.dart'; import 'package:solian/theme.dart'; import 'package:solian/widgets/loading_indicator.dart'; import 'package:solian/widgets/posts/post_item.dart'; import 'package:solian/widgets/posts/post_replies.dart'; class PostDetailScreen extends StatefulWidget { final String id; final Post? post; const PostDetailScreen({ super.key, required this.id, this.post, }); @override State createState() => _PostDetailScreenState(); } class _PostDetailScreenState extends State { bool _isBusy = true; Post? _item; Future _getDetail() async { final PostProvider posts = Get.find(); try { final resp = await posts.getPost(widget.id); _item = Post.fromJson(resp.body); } catch (e) { context.showErrorDialog(e).then((_) => Navigator.pop(context)); } Get.find().feedLastReadAt = _item?.id; setState(() => _isBusy = false); } @override void initState() { super.initState(); if (widget.post != null) { _item = widget.post; } _getDetail(); } @override Widget build(BuildContext context) { if (_isBusy && _item == null) { return const Center( child: CircularProgressIndicator(), ); } return CustomScrollView( slivers: [ if (_isBusy) SliverToBoxAdapter( child: LoadingIndicator(), ), SliverToBoxAdapter( child: PostItem( item: _item!, isClickable: false, isOverrideEmbedClickable: true, isFullDate: true, isShowReply: false, isContentSelectable: true, padding: AppTheme.isLargeScreen(context) ? EdgeInsets.symmetric( horizontal: 4, vertical: 8, ) : EdgeInsets.zero, ), ), 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), ), ], ); } }