mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
show comments in comic details page
This commit is contained in:
@@ -115,6 +115,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
buildDescription(),
|
||||
buildInfo(),
|
||||
buildChapters(),
|
||||
buildComments(),
|
||||
buildThumbnails(),
|
||||
buildRecommend(),
|
||||
SliverPadding(padding: EdgeInsets.only(bottom: context.padding.bottom)),
|
||||
@@ -287,7 +288,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
onLongPressed: quickFavorite,
|
||||
iconColor: context.useTextColor(Colors.purple),
|
||||
),
|
||||
if (comicSource.commentsLoader != null)
|
||||
if (comicSource.commentsLoader != null && comic.comments == null)
|
||||
_ActionButton(
|
||||
icon: const Icon(Icons.comment),
|
||||
text: (comic.commentsCount ?? 'Comments'.tl).toString(),
|
||||
@@ -549,6 +550,16 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
SliverGridComics(comics: comic.recommend!),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget buildComments() {
|
||||
if (comic.comments == null || comic.comments!.isEmpty) {
|
||||
return const SliverPadding(padding: EdgeInsets.zero);
|
||||
}
|
||||
return _CommentsPart(
|
||||
comments: comic.comments!,
|
||||
showMore: showComments,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract mixin class _ComicPageActions {
|
||||
@@ -1670,3 +1681,148 @@ class _SelectDownloadChapterState extends State<_SelectDownloadChapter> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CommentsPart extends StatefulWidget {
|
||||
const _CommentsPart({
|
||||
required this.comments,
|
||||
required this.showMore,
|
||||
});
|
||||
|
||||
final List<Comment> comments;
|
||||
|
||||
final void Function() showMore;
|
||||
|
||||
@override
|
||||
State<_CommentsPart> createState() => _CommentsPartState();
|
||||
}
|
||||
|
||||
class _CommentsPartState extends State<_CommentsPart> {
|
||||
final scrollController = ScrollController();
|
||||
|
||||
late List<Comment> comments;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
comments = widget.comments;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiSliver(
|
||||
children: [
|
||||
SliverToBoxAdapter(
|
||||
child: ListTile(
|
||||
title: Text("Comments".tl),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_left),
|
||||
onPressed: () {
|
||||
scrollController.animateTo(
|
||||
scrollController.position.pixels - 340,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.ease,
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
onPressed: () {
|
||||
scrollController.animateTo(
|
||||
scrollController.position.pixels + 340,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.ease,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 184,
|
||||
child: ListView.builder(
|
||||
controller: scrollController,
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: comments.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _CommentWidget(comment: comments[index]);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_ActionButton(
|
||||
icon: const Icon(Icons.comment),
|
||||
text: "View more".tl,
|
||||
onPressed: widget.showMore,
|
||||
iconColor: context.useTextColor(Colors.green),
|
||||
).fixHeight(48).paddingRight(8).toAlign(Alignment.centerRight),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SliverToBoxAdapter(
|
||||
child: Divider(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CommentWidget extends StatelessWidget {
|
||||
const _CommentWidget({required this.comment});
|
||||
|
||||
final Comment comment;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: double.infinity,
|
||||
margin: const EdgeInsets.fromLTRB(16, 8, 0, 8),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
width: 324,
|
||||
decoration: BoxDecoration(
|
||||
color: context.colorScheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
if (comment.avatar != null)
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
color: context.colorScheme.surfaceContainer,
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Image(
|
||||
image: CachedImageProvider(comment.avatar!),
|
||||
width: 36,
|
||||
height: 36,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
).paddingRight(8),
|
||||
Text(comment.userName, style: ts.bold),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Expanded(
|
||||
child: RichCommentContent(text: comment.content).fixWidth(324),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
if (comment.time != null)
|
||||
Text(comment.time!, style: ts.s12).toAlign(Alignment.centerLeft),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user