game comments
This commit is contained in:
parent
1011621f09
commit
e694e7e706
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/go-flutter-desktop/plugins/url_launcher v0.1.2
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20201108214237-06ea97f0c265
|
||||
github.com/miguelpruivo/flutter_file_picker/go v0.0.0-20210622152105-9f0a811028a0
|
||||
github.com/niuhuan/pica-go v0.0.0-20211105060849-4f6ae99a942e
|
||||
github.com/niuhuan/pica-go v0.0.0-20211109050119-cf22461c638f
|
||||
github.com/pkg/errors v0.9.1
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
|
||||
golang.org/x/mobile v0.0.0-20210924032853-1c027f395ef7 // indirect
|
||||
|
|
|
@ -41,6 +41,12 @@ github.com/niuhuan/pica-go v0.0.0-20211102035530-65029bd4ee97 h1:wlsmZVsLrZ/dB1K
|
|||
github.com/niuhuan/pica-go v0.0.0-20211102035530-65029bd4ee97/go.mod h1:fx2m+OgMeEZf6/TrfblV9i85SjPsOGbnjIL2gohxP4M=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211105060849-4f6ae99a942e h1:NR/RCPlbx7cMjk7p8GqfkhOqWTH6vyfgYq7Vubjn9mY=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211105060849-4f6ae99a942e/go.mod h1:fx2m+OgMeEZf6/TrfblV9i85SjPsOGbnjIL2gohxP4M=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211109012708-2cef9976dbaa h1:PnIE6Ltz/dy9K1jZCGfTvPDHGitSwXVvQfzwgVIJSWE=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211109012708-2cef9976dbaa/go.mod h1:fx2m+OgMeEZf6/TrfblV9i85SjPsOGbnjIL2gohxP4M=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211109043215-974462cb2b0d h1:jwZdWp1PkEbWAi/w3cI+4kBvIyxHtZgVmFFOu7XnABw=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211109043215-974462cb2b0d/go.mod h1:fx2m+OgMeEZf6/TrfblV9i85SjPsOGbnjIL2gohxP4M=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211109050119-cf22461c638f h1:SQ6vAF7nyIDjhUj/SsEHRlxae4XLtygSuxWrJJazN1g=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211109050119-cf22461c638f/go.mod h1:fx2m+OgMeEZf6/TrfblV9i85SjPsOGbnjIL2gohxP4M=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
|
|
@ -425,6 +425,23 @@ func postChildComment(params string) (string, error) {
|
|||
return "", nil
|
||||
}
|
||||
|
||||
func postGameChildComment(params string) (string, error) {
|
||||
var paramsStruct struct {
|
||||
GameId string `json:"gameId"`
|
||||
CommentId string `json:"commentId"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
json.Unmarshal([]byte(params), ¶msStruct)
|
||||
err := client.PostChildComment(paramsStruct.CommentId, paramsStruct.Content)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
network_cache.RemoveCaches(fmt.Sprintf("GAME_COMMENT_CHILDREN$%s$%%", paramsStruct.CommentId))
|
||||
network_cache.RemoveCaches("MY_COMMENTS$%")
|
||||
network_cache.RemoveCaches(fmt.Sprintf("GAME_COMMENTS$%s$%%", paramsStruct.GameId))
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func switchLikeComment(params string) (string, error) {
|
||||
var paramsStruct struct {
|
||||
CommentId string `json:"commentId"`
|
||||
|
@ -478,3 +495,68 @@ func game(gameId string) (string, error) {
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
func gameComments(params string) (string, error) {
|
||||
var paramsStruct struct {
|
||||
GameId string `json:"gameId"`
|
||||
Page int `json:"page"`
|
||||
}
|
||||
json.Unmarshal([]byte(params), ¶msStruct)
|
||||
gameId := paramsStruct.GameId
|
||||
page := paramsStruct.Page
|
||||
return cacheable(
|
||||
fmt.Sprintf("GAME_COMMENTS$%s$%d", gameId, page),
|
||||
time.Hour*2,
|
||||
func() (interface{}, error) {
|
||||
return client.GameCommentsPage(gameId, page)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func postGameComment(params string) (string, error) {
|
||||
var paramsStruct struct {
|
||||
GameId string `json:"gameId"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
json.Unmarshal([]byte(params), ¶msStruct)
|
||||
err := client.PostGameComment(paramsStruct.GameId, paramsStruct.Content)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
network_cache.RemoveCaches("MY_COMMENTS$%")
|
||||
network_cache.RemoveCaches(fmt.Sprintf("GAME_COMMENTS$%s$%%", paramsStruct.GameId))
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func gameCommentChildren(params string) (string, error) {
|
||||
var paramsStruct struct {
|
||||
CommentId string `json:"commentId"`
|
||||
Page int `json:"page"`
|
||||
}
|
||||
json.Unmarshal([]byte(params), ¶msStruct)
|
||||
commentId := paramsStruct.CommentId
|
||||
page := paramsStruct.Page
|
||||
return cacheable(
|
||||
fmt.Sprintf("GAME_COMMENT_CHILDREN$%s$%d", commentId, page),
|
||||
time.Hour*2,
|
||||
func() (interface{}, error) {
|
||||
return client.GameCommentChildren(commentId, page)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func switchLikeGameComment(params string) (string, error) {
|
||||
var paramsStruct struct {
|
||||
CommentId string `json:"commentId"`
|
||||
GameId string `json:"gameId"`
|
||||
}
|
||||
json.Unmarshal([]byte(params), ¶msStruct)
|
||||
rsp, err := client.SwitchLikeComment(paramsStruct.CommentId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
network_cache.RemoveCaches(fmt.Sprintf("GAME_COMMENT_CHILDREN$%s$%%", paramsStruct.CommentId))
|
||||
network_cache.RemoveCaches("MY_COMMENTS$%")
|
||||
network_cache.RemoveCaches(fmt.Sprintf("GAME_COMMENTS$%s$%%", paramsStruct.GameId))
|
||||
return *rsp, nil
|
||||
}
|
||||
|
|
|
@ -585,6 +585,16 @@ func FlatInvoke(method string, params string) (string, error) {
|
|||
return game(params)
|
||||
case "games":
|
||||
return games(params)
|
||||
case "gameComments":
|
||||
return gameComments(params)
|
||||
case "postGameComment":
|
||||
return postGameComment(params)
|
||||
case "gameCommentChildren":
|
||||
return gameCommentChildren(params)
|
||||
case "switchLikeGameComment":
|
||||
return switchLikeGameComment(params)
|
||||
case "postGameChildComment":
|
||||
return postGameChildComment(params)
|
||||
case "viewLogPage":
|
||||
return viewLogPage(params)
|
||||
case "clearAllViewLog":
|
||||
|
|
|
@ -66,6 +66,8 @@ class Page {
|
|||
this.page = json["page"];
|
||||
this.pages = json["pages"];
|
||||
}
|
||||
|
||||
Page.of(this.total, this.limit, this.page, this.pages);
|
||||
}
|
||||
|
||||
/// 分类
|
||||
|
@ -255,12 +257,10 @@ class CommentPage extends Page {
|
|||
}
|
||||
}
|
||||
|
||||
/// 漫画评论详情
|
||||
class Comment {
|
||||
class CommentBase {
|
||||
late String id;
|
||||
late String content;
|
||||
late CommentUser user;
|
||||
late String comic;
|
||||
late bool isTop;
|
||||
late bool hide;
|
||||
late String createdAt;
|
||||
|
@ -268,11 +268,10 @@ class Comment {
|
|||
late int commentsCount;
|
||||
late bool isLiked;
|
||||
|
||||
Comment.fromJson(Map<String, dynamic> json) {
|
||||
CommentBase.fromJson(Map<String, dynamic> json) {
|
||||
this.id = json["_id"];
|
||||
this.content = json["content"];
|
||||
this.user = CommentUser.fromJson(Map<String, dynamic>.of(json["_user"]));
|
||||
this.comic = json["_comic"];
|
||||
this.isTop = json["isTop"];
|
||||
this.hide = json["hide"];
|
||||
this.createdAt = json["created_at"];
|
||||
|
@ -282,6 +281,24 @@ class Comment {
|
|||
}
|
||||
}
|
||||
|
||||
/// 子评论
|
||||
class ChildOfComment extends Comment {
|
||||
late String parent;
|
||||
|
||||
ChildOfComment.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
this.parent = json["_parent"];
|
||||
}
|
||||
}
|
||||
|
||||
/// 漫画评论详情
|
||||
class Comment extends CommentBase {
|
||||
late String comic;
|
||||
|
||||
Comment.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
this.comic = json["_comic"];
|
||||
}
|
||||
}
|
||||
|
||||
/// 评论的用户信息
|
||||
class CommentUser extends BasicUser {
|
||||
late String role;
|
||||
|
@ -604,10 +621,54 @@ class CommentChildrenPage extends Page {
|
|||
}
|
||||
|
||||
/// 子评论
|
||||
class CommentChild extends Comment {
|
||||
late String parent;
|
||||
class CommentChild extends ChildOfComment {
|
||||
late String comic;
|
||||
|
||||
CommentChild.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
this.parent = json["_parent"];
|
||||
this.comic = json["_comic"];
|
||||
}
|
||||
}
|
||||
|
||||
/// 漫画评论分页
|
||||
class GameCommentPage extends Page {
|
||||
late List<GameComment> docs;
|
||||
|
||||
GameCommentPage.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
this.docs = List.from(json["docs"])
|
||||
.map((e) => Map<String, dynamic>.from(e))
|
||||
.map((e) => GameComment.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
/// 游戏评论
|
||||
class GameComment extends CommentBase {
|
||||
late String game;
|
||||
|
||||
GameComment.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
this.game = json["_game"];
|
||||
}
|
||||
}
|
||||
|
||||
/// 子评论分页
|
||||
class GameCommentChildrenPage extends Page {
|
||||
late List<GameCommentChild> docs;
|
||||
|
||||
GameCommentChildrenPage.fromJson(Map<String, dynamic> json)
|
||||
: super.fromJson(json) {
|
||||
this.docs = [];
|
||||
if (json["docs"] != null) {
|
||||
docs.addAll(
|
||||
List.of(json["docs"]).map((e) => GameCommentChild.fromJson(e)).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 子评论
|
||||
class GameCommentChild extends ChildOfComment {
|
||||
late String game;
|
||||
|
||||
GameCommentChild.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
this.game = json["_game"];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -322,6 +322,14 @@ class Method {
|
|||
return CommentChildrenPage.fromJson(json.decode(rsp));
|
||||
}
|
||||
|
||||
/// 喜欢/取消喜欢 一条评论
|
||||
Future switchLikeComment(String commentId, String comicId) {
|
||||
return _flatInvoke("switchLikeComment", {
|
||||
"commentId": commentId,
|
||||
"comicId": comicId,
|
||||
});
|
||||
}
|
||||
|
||||
/// 我的评论列表
|
||||
Future<MyCommentsPage> myComments(int page) async {
|
||||
String response = await _flatInvoke("myComments", "$page");
|
||||
|
@ -360,6 +368,53 @@ class Method {
|
|||
return GameInfo.fromJson(json.decode(data));
|
||||
}
|
||||
|
||||
/// 游戏的评论列表
|
||||
Future<GameCommentPage> gameComments(String gameId, int page) async {
|
||||
var rsp = await _flatInvoke("gameComments", {
|
||||
"gameId": gameId,
|
||||
"page": page,
|
||||
});
|
||||
return GameCommentPage.fromJson(json.decode(rsp));
|
||||
}
|
||||
|
||||
/// 对游戏发送评论
|
||||
Future<dynamic> postGameComment(String gameId, String content) {
|
||||
return _flatInvoke("postGameComment", {
|
||||
"gameId": gameId,
|
||||
"content": content,
|
||||
});
|
||||
}
|
||||
|
||||
/// 拉取游戏子评论
|
||||
Future<GameCommentChildrenPage> gameCommentChildren(
|
||||
String gameId,
|
||||
String commentId,
|
||||
int page,
|
||||
) async {
|
||||
var rsp = await _flatInvoke("gameCommentChildren", {
|
||||
"gameId": gameId,
|
||||
"commentId": commentId,
|
||||
"page": page,
|
||||
});
|
||||
return GameCommentChildrenPage.fromJson(json.decode(rsp));
|
||||
}
|
||||
|
||||
/// 喜欢/取消喜欢 一条游戏评论
|
||||
Future switchLikeGameComment(String commentId, String gameId) {
|
||||
return _flatInvoke("switchLikeGameComment", {
|
||||
"commentId": commentId,
|
||||
"gameId": gameId,
|
||||
});
|
||||
}
|
||||
|
||||
/// 发送游戏子评论
|
||||
Future<dynamic> postGameChildComment(String commentId, String content) {
|
||||
return _flatInvoke("postGameChildComment", {
|
||||
"commentId": commentId,
|
||||
"content": content,
|
||||
});
|
||||
}
|
||||
|
||||
/// 清理网络缓存
|
||||
Future cleanNetworkCache() {
|
||||
return _flatInvoke("cleanNetworkCache", "");
|
||||
|
@ -611,14 +666,6 @@ class Method {
|
|||
return _flatInvoke("saveDownloadThreadCount", "$value");
|
||||
}
|
||||
|
||||
/// 喜欢/取消喜欢 一条评论
|
||||
Future switchLikeComment(String commentId, String comicId) {
|
||||
return _flatInvoke("switchLikeComment", {
|
||||
"commentId": commentId,
|
||||
"comicId": comicId,
|
||||
});
|
||||
}
|
||||
|
||||
/// 转化为PNG
|
||||
Future<Uint8List> convertToPNG(String path) async {
|
||||
return await _channel.invokeMethod("convertToPNG", {"path": path});
|
||||
|
|
|
@ -5,11 +5,12 @@ import 'package:pikapi/basic/Cross.dart';
|
|||
import 'package:pikapi/basic/Entities.dart';
|
||||
import 'package:pikapi/screens/ComicsScreen.dart';
|
||||
import 'package:pikapi/basic/Navigatior.dart';
|
||||
import 'package:pikapi/screens/components/CommentMainType.dart';
|
||||
import 'package:pikapi/screens/components/ItemBuilder.dart';
|
||||
import 'package:pikapi/basic/Method.dart';
|
||||
import 'ComicReaderScreen.dart';
|
||||
import 'DownloadConfirmScreen.dart';
|
||||
import 'components/ComicCommentList.dart';
|
||||
import 'components/CommentList.dart';
|
||||
import 'components/ComicDescriptionCard.dart';
|
||||
import 'components/ComicInfoCard.dart';
|
||||
import 'components/ComicTagsCard.dart';
|
||||
|
@ -104,7 +105,7 @@ class _ComicInfoScreenState extends State<ComicInfoScreen> with RouteAware {
|
|||
];
|
||||
var _views = <Widget>[
|
||||
_buildEpWrap(_epListFuture, _comicInfo),
|
||||
ComicCommentList(_comicInfo.id),
|
||||
CommentList(CommentMainType.COMIC, _comicInfo.id),
|
||||
];
|
||||
return DefaultTabController(
|
||||
length: _tabs.length,
|
||||
|
|
|
@ -1,15 +1,34 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:pikapi/basic/Common.dart';
|
||||
import 'package:pikapi/basic/Entities.dart';
|
||||
import 'package:pikapi/basic/Entities.dart' as e;
|
||||
import 'package:pikapi/basic/Method.dart';
|
||||
import 'package:pikapi/screens/components/ComicCommentItem.dart';
|
||||
import 'package:pikapi/screens/components/CommentItem.dart';
|
||||
import 'package:pikapi/screens/components/CommentMainType.dart';
|
||||
import 'package:pikapi/screens/components/ContentBuilder.dart';
|
||||
|
||||
class CommentScreen extends StatefulWidget {
|
||||
final String comicId;
|
||||
final Comment comment;
|
||||
class _CommentChildPage extends e.Page {
|
||||
late List<ChildOfComment> docs;
|
||||
|
||||
const CommentScreen(this.comicId, this.comment);
|
||||
_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;
|
||||
}
|
||||
}
|
||||
|
||||
class CommentScreen extends StatefulWidget {
|
||||
final CommentMainType mainType;
|
||||
final String mainId;
|
||||
final CommentBase comment;
|
||||
|
||||
const CommentScreen(this.mainType, this.mainId, this.comment);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CommentScreenState();
|
||||
|
@ -17,14 +36,23 @@ class CommentScreen extends StatefulWidget {
|
|||
|
||||
class _CommentScreenState extends State<CommentScreen> {
|
||||
late int _currentPage = 1;
|
||||
late Future<CommentChildrenPage> _future = _loadPage();
|
||||
late Future<_CommentChildPage> _future = _loadPage();
|
||||
|
||||
Future<CommentChildrenPage> _loadPage() {
|
||||
return method.commentChildren(
|
||||
widget.comicId,
|
||||
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,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildChildrenPager() {
|
||||
|
@ -32,7 +60,7 @@ class _CommentScreenState extends State<CommentScreen> {
|
|||
future: _future,
|
||||
onRefresh: _loadPage,
|
||||
successBuilder:
|
||||
(BuildContext context, AsyncSnapshot<CommentChildrenPage> snapshot) {
|
||||
(BuildContext context, AsyncSnapshot<_CommentChildPage> snapshot) {
|
||||
var page = snapshot.data!;
|
||||
return ListView(
|
||||
children: [
|
||||
|
@ -54,7 +82,7 @@ class _CommentScreenState extends State<CommentScreen> {
|
|||
),
|
||||
body: Column(
|
||||
children: [
|
||||
ComicCommentItem(widget.comment, widget.comicId),
|
||||
ComicCommentItem(widget.mainType, widget.mainId, widget.comment),
|
||||
Container(
|
||||
height: 3,
|
||||
color:
|
||||
|
@ -67,8 +95,8 @@ class _CommentScreenState extends State<CommentScreen> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildComment(CommentChild e) {
|
||||
return ComicCommentItem(e, widget.comicId);
|
||||
Widget _buildComment(CommentBase e) {
|
||||
return ComicCommentItem(widget.mainType, widget.mainId, e);
|
||||
}
|
||||
|
||||
Widget _buildPostComment() {
|
||||
|
@ -77,7 +105,14 @@ class _CommentScreenState extends State<CommentScreen> {
|
|||
String? text = await inputString(context, '请输入评论内容');
|
||||
if (text != null && text.isNotEmpty) {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
setState(() {
|
||||
_future = _loadPage();
|
||||
widget.comment.commentsCount++;
|
||||
|
@ -110,7 +145,7 @@ class _CommentScreenState extends State<CommentScreen> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildPrePage(CommentChildrenPage page) {
|
||||
Widget _buildPrePage(_CommentChildPage page) {
|
||||
if (page.page > 1) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
|
@ -130,7 +165,7 @@ class _CommentScreenState extends State<CommentScreen> {
|
|||
return Container();
|
||||
}
|
||||
|
||||
Widget _buildNextPage(CommentChildrenPage page) {
|
||||
Widget _buildNextPage(_CommentChildPage page) {
|
||||
if (page.page < page.pages) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
|
|
|
@ -2,11 +2,13 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:pikapi/basic/Entities.dart';
|
||||
import 'package:pikapi/basic/Method.dart';
|
||||
import 'package:pikapi/screens/components/CommentMainType.dart';
|
||||
import 'package:pikapi/screens/components/ContentError.dart';
|
||||
import 'package:pikapi/screens/components/ContentLoading.dart';
|
||||
import 'package:pikapi/screens/components/Images.dart';
|
||||
|
||||
import 'GameDownloadScreen.dart';
|
||||
import 'components/CommentList.dart';
|
||||
import 'components/GameTitleCard.dart';
|
||||
|
||||
// 游戏详情
|
||||
|
@ -59,7 +61,9 @@ class _GameInfoScreenState extends State<GameInfoScreen> {
|
|||
return LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
var info = snapshot.data!;
|
||||
return Scaffold(
|
||||
return DefaultTabController(
|
||||
length: 2,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(info.title),
|
||||
),
|
||||
|
@ -68,7 +72,10 @@ class _GameInfoScreenState extends State<GameInfoScreen> {
|
|||
GameTitleCard(info),
|
||||
Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20, right: 20, top: 5, bottom: 10,
|
||||
left: 20,
|
||||
right: 20,
|
||||
top: 5,
|
||||
bottom: 10,
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(5)),
|
||||
|
@ -79,7 +86,8 @@ class _GameInfoScreenState extends State<GameInfoScreen> {
|
|||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => GameDownloadScreen(info)),
|
||||
builder: (context) =>
|
||||
GameDownloadScreen(info)),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
|
@ -119,16 +127,51 @@ class _GameInfoScreenState extends State<GameInfoScreen> {
|
|||
.toList(),
|
||||
),
|
||||
),
|
||||
Container(height: 20),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Text(info.description, style: descriptionStyle),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 40,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondary
|
||||
.withOpacity(.025),
|
||||
child: TabBar(
|
||||
tabs: <Widget>[
|
||||
Tab(text: '详情 '),
|
||||
Tab(text: '评论 (${info.commentsCount})'),
|
||||
],
|
||||
indicatorColor:
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
labelColor:
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
onTap: (val) async {
|
||||
setState(() {
|
||||
_tabIndex = val;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_tabIndex == 0
|
||||
? Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child:
|
||||
Text(info.description, style: descriptionStyle),
|
||||
)
|
||||
: CommentList(CommentMainType.GAME, info.id),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
var _tabIndex = 0;
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@ import 'package:pikapi/basic/Entities.dart';
|
|||
import 'package:pikapi/basic/Method.dart';
|
||||
|
||||
import 'Avatar.dart';
|
||||
import 'CommentMainType.dart';
|
||||
|
||||
class ComicCommentItem extends StatefulWidget {
|
||||
final String comicId;
|
||||
final Comment comment;
|
||||
final CommentMainType mainType;
|
||||
final String mainId;
|
||||
final CommentBase comment;
|
||||
|
||||
const ComicCommentItem(this.comment, this.comicId);
|
||||
const ComicCommentItem(this.mainType, this.mainId, this.comment);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ComicCommentItem();
|
||||
|
@ -21,7 +23,6 @@ class _ComicCommentItem extends State<ComicCommentItem> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var comment = widget.comment;
|
||||
var comicId = widget.comicId;
|
||||
var theme = Theme.of(context);
|
||||
var nameStyle = TextStyle(fontWeight: FontWeight.bold);
|
||||
var levelStyle = TextStyle(
|
||||
|
@ -111,10 +112,20 @@ class _ComicCommentItem extends State<ComicCommentItem> {
|
|||
likeLoading = true;
|
||||
});
|
||||
try {
|
||||
switch (widget.mainType) {
|
||||
case CommentMainType.COMIC:
|
||||
await method.switchLikeComment(
|
||||
comment.id,
|
||||
comicId,
|
||||
widget.mainId,
|
||||
);
|
||||
break;
|
||||
case CommentMainType.GAME:
|
||||
await method.switchLikeGameComment(
|
||||
comment.id,
|
||||
widget.mainId,
|
||||
);
|
||||
break;
|
||||
}
|
||||
setState(() {
|
||||
if (comment.isLiked) {
|
||||
comment.isLiked = false;
|
|
@ -1,27 +1,55 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:pikapi/basic/Common.dart';
|
||||
import 'package:pikapi/basic/Entities.dart';
|
||||
import 'package:pikapi/basic/Entities.dart' as e;
|
||||
import 'package:pikapi/screens/CommentScreen.dart';
|
||||
import 'package:pikapi/screens/components/ItemBuilder.dart';
|
||||
import 'package:pikapi/basic/Method.dart';
|
||||
import 'ComicCommentItem.dart';
|
||||
import 'CommentItem.dart';
|
||||
import 'CommentMainType.dart';
|
||||
|
||||
// 漫画的评论列表
|
||||
class ComicCommentList extends StatefulWidget {
|
||||
final String comicId;
|
||||
class _CommentBasePage extends e.Page {
|
||||
late List<CommentBase> docs;
|
||||
|
||||
ComicCommentList(this.comicId);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ComicCommentListState();
|
||||
_CommentBasePage.ofComic(CommentPage commentPage)
|
||||
: super.of(commentPage.total, commentPage.limit, commentPage.page,
|
||||
commentPage.pages) {
|
||||
this.docs = commentPage.docs;
|
||||
}
|
||||
|
||||
class _ComicCommentListState extends State<ComicCommentList> {
|
||||
late int _currentPage = 1;
|
||||
late Future<CommentPage> _future = _loadPage();
|
||||
_CommentBasePage.ofGame(GameCommentPage commentPage)
|
||||
: super.of(commentPage.total, commentPage.limit, commentPage.page,
|
||||
commentPage.pages) {
|
||||
this.docs = commentPage.docs;
|
||||
}
|
||||
}
|
||||
|
||||
Future<CommentPage> _loadPage() {
|
||||
return method.comments(widget.comicId, _currentPage);
|
||||
// 漫画的评论列表
|
||||
class CommentList extends StatefulWidget {
|
||||
final CommentMainType mainType;
|
||||
final String mainId;
|
||||
|
||||
CommentList(this.mainType, this.mainId);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CommentListState();
|
||||
}
|
||||
|
||||
class _CommentListState extends State<CommentList> {
|
||||
late int _currentPage = 1;
|
||||
late Future<_CommentBasePage> _future = _loadPage();
|
||||
|
||||
Future<_CommentBasePage> _loadPage() async {
|
||||
switch (widget.mainType) {
|
||||
case CommentMainType.COMIC:
|
||||
return _CommentBasePage.ofComic(
|
||||
await method.comments(widget.mainId, _currentPage),
|
||||
);
|
||||
case CommentMainType.GAME:
|
||||
return _CommentBasePage.ofGame(
|
||||
await method.gameComments(widget.mainId, _currentPage),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -29,7 +57,7 @@ class _ComicCommentListState extends State<ComicCommentList> {
|
|||
return ItemBuilder(
|
||||
future: _future,
|
||||
successBuilder:
|
||||
(BuildContext context, AsyncSnapshot<CommentPage> snapshot) {
|
||||
(BuildContext context, AsyncSnapshot<_CommentBasePage> snapshot) {
|
||||
var page = snapshot.data!;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
|
@ -50,16 +78,17 @@ class _ComicCommentListState extends State<ComicCommentList> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildComment(Comment comment) {
|
||||
Widget _buildComment(CommentBase comment) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CommentScreen(widget.comicId, comment),
|
||||
builder: (context) =>
|
||||
CommentScreen(widget.mainType, widget.mainId, comment),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: ComicCommentItem(comment, widget.comicId),
|
||||
child: ComicCommentItem(widget.mainType, widget.mainId, comment),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -69,7 +98,14 @@ class _ComicCommentListState extends State<ComicCommentList> {
|
|||
String? text = await inputString(context, '请输入评论内容');
|
||||
if (text != null && text.isNotEmpty) {
|
||||
try {
|
||||
await method.postComment(widget.comicId, text);
|
||||
switch (widget.mainType) {
|
||||
case CommentMainType.COMIC:
|
||||
await method.postComment(widget.mainId, text);
|
||||
break;
|
||||
case CommentMainType.GAME:
|
||||
await method.postGameComment(widget.mainId, text);
|
||||
break;
|
||||
}
|
||||
setState(() {
|
||||
_future = _loadPage();
|
||||
});
|
||||
|
@ -101,7 +137,7 @@ class _ComicCommentListState extends State<ComicCommentList> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildPrePage(CommentPage page) {
|
||||
Widget _buildPrePage(_CommentBasePage page) {
|
||||
if (page.page > 1) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
|
@ -121,7 +157,7 @@ class _ComicCommentListState extends State<ComicCommentList> {
|
|||
return Container();
|
||||
}
|
||||
|
||||
Widget _buildNextPage(CommentPage page) {
|
||||
Widget _buildNextPage(_CommentBasePage page) {
|
||||
if (page.page < page.pages) {
|
||||
return InkWell(
|
||||
onTap: () {
|
|
@ -0,0 +1,4 @@
|
|||
enum CommentMainType {
|
||||
COMIC,
|
||||
GAME,
|
||||
}
|
Loading…
Reference in New Issue