2021-09-29 23:57:09 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-11-11 03:00:38 +00:00
|
|
|
import 'package:pikapika/basic/Common.dart';
|
|
|
|
import 'package:pikapika/basic/Entities.dart';
|
|
|
|
import 'package:pikapika/basic/Entities.dart' as e;
|
|
|
|
import 'package:pikapika/basic/Method.dart';
|
|
|
|
import 'package:pikapika/screens/components/CommentItem.dart';
|
|
|
|
import 'package:pikapika/screens/components/CommentMainType.dart';
|
|
|
|
import 'package:pikapika/screens/components/ContentBuilder.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
|
2021-11-09 21:57:44 +00:00
|
|
|
class _CommentChildPage extends e.Page {
|
|
|
|
late List<ChildOfComment> docs;
|
|
|
|
|
|
|
|
_CommentChildPage.ofComic(CommentChildrenPage commentPage)
|
|
|
|
: super.of(commentPage.total, commentPage.limit, commentPage.page,
|
|
|
|
commentPage.pages) {
|
|
|
|
this.docs = commentPage.docs;
|
|
|
|
}
|
|
|
|
|
|
|
|
_CommentChildPage.ofGame(GameCommentChildrenPage commentPage)
|
|
|
|
: super.of(commentPage.total, commentPage.limit, commentPage.page,
|
|
|
|
commentPage.pages) {
|
|
|
|
this.docs = commentPage.docs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 23:57:09 +00:00
|
|
|
class CommentScreen extends StatefulWidget {
|
2021-11-09 21:57:44 +00:00
|
|
|
final CommentMainType mainType;
|
|
|
|
final String mainId;
|
|
|
|
final CommentBase comment;
|
2021-09-29 23:57:09 +00:00
|
|
|
|
2021-11-09 21:57:44 +00:00
|
|
|
const CommentScreen(this.mainType, this.mainId, this.comment);
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _CommentScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CommentScreenState extends State<CommentScreen> {
|
|
|
|
late int _currentPage = 1;
|
2021-11-09 21:57:44 +00:00
|
|
|
late Future<_CommentChildPage> _future = _loadPage();
|
2021-09-29 23:57:09 +00:00
|
|
|
|
2021-11-09 21:57:44 +00:00
|
|
|
Future<_CommentChildPage> _loadPage() async {
|
|
|
|
switch (widget.mainType) {
|
|
|
|
case CommentMainType.COMIC:
|
|
|
|
return _CommentChildPage.ofComic(await method.commentChildren(
|
|
|
|
widget.mainId,
|
|
|
|
widget.comment.id,
|
|
|
|
_currentPage,
|
|
|
|
));
|
|
|
|
case CommentMainType.GAME:
|
|
|
|
return _CommentChildPage.ofGame(await method.gameCommentChildren(
|
|
|
|
widget.mainId,
|
|
|
|
widget.comment.id,
|
|
|
|
_currentPage,
|
|
|
|
));
|
|
|
|
}
|
2021-09-29 23:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildChildrenPager() {
|
|
|
|
return ContentBuilder(
|
|
|
|
future: _future,
|
|
|
|
onRefresh: _loadPage,
|
|
|
|
successBuilder:
|
2021-11-09 21:57:44 +00:00
|
|
|
(BuildContext context, AsyncSnapshot<_CommentChildPage> snapshot) {
|
2021-09-29 23:57:09 +00:00
|
|
|
var page = snapshot.data!;
|
|
|
|
return ListView(
|
|
|
|
children: [
|
|
|
|
_buildPrePage(page),
|
|
|
|
...page.docs.map((e) => _buildComment(e)),
|
|
|
|
_buildNextPage(page),
|
2022-01-13 06:19:57 +00:00
|
|
|
_buildPostComment(),
|
2021-09-29 23:57:09 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('评论'),
|
|
|
|
),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
2021-11-09 21:57:44 +00:00
|
|
|
ComicCommentItem(widget.mainType, widget.mainId, widget.comment),
|
2021-09-29 23:57:09 +00:00
|
|
|
Container(
|
|
|
|
height: 3,
|
|
|
|
color:
|
|
|
|
(Theme.of(context).textTheme.bodyText1?.color ?? Colors.black)
|
|
|
|
.withOpacity(.05),
|
|
|
|
),
|
|
|
|
Expanded(child: _buildChildrenPager())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:57:44 +00:00
|
|
|
Widget _buildComment(CommentBase e) {
|
|
|
|
return ComicCommentItem(widget.mainType, widget.mainId, e);
|
2021-09-29 23:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildPostComment() {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () async {
|
|
|
|
String? text = await inputString(context, '请输入评论内容');
|
|
|
|
if (text != null && text.isNotEmpty) {
|
|
|
|
try {
|
2021-11-09 21:57:44 +00:00
|
|
|
switch (widget.mainType) {
|
|
|
|
case CommentMainType.COMIC:
|
|
|
|
await method.postChildComment(widget.comment.id, text);
|
|
|
|
break;
|
|
|
|
case CommentMainType.GAME:
|
|
|
|
await method.postGameChildComment(widget.comment.id, text);
|
|
|
|
break;
|
|
|
|
}
|
2021-09-29 23:57:09 +00:00
|
|
|
setState(() {
|
|
|
|
_future = _loadPage();
|
|
|
|
widget.comment.commentsCount++;
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
defaultToast(context, "评论失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
top: BorderSide(
|
|
|
|
width: .25,
|
|
|
|
style: BorderStyle.solid,
|
|
|
|
color: Colors.grey.shade500.withOpacity(.5),
|
|
|
|
),
|
|
|
|
bottom: BorderSide(
|
|
|
|
width: .25,
|
|
|
|
style: BorderStyle.solid,
|
|
|
|
color: Colors.grey.shade500.withOpacity(.5),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.all(30),
|
|
|
|
child: Center(
|
|
|
|
child: Text('我有话要讲'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:57:44 +00:00
|
|
|
Widget _buildPrePage(_CommentChildPage page) {
|
2021-09-29 23:57:09 +00:00
|
|
|
if (page.page > 1) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
_currentPage = page.page - 1;
|
|
|
|
_future = _loadPage();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(30),
|
|
|
|
child: Center(
|
|
|
|
child: Text('上一页'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:57:44 +00:00
|
|
|
Widget _buildNextPage(_CommentChildPage page) {
|
2021-09-29 23:57:09 +00:00
|
|
|
if (page.page < page.pages) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
_currentPage = page.page + 1;
|
|
|
|
_future = _loadPage();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(30),
|
|
|
|
child: Center(
|
|
|
|
child: Text('下一页'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
}
|