diff --git a/lib/common/widgets/network_img_layer.dart b/lib/common/widgets/network_img_layer.dart index 832e46d5a..6e15528df 100644 --- a/lib/common/widgets/network_img_layer.dart +++ b/lib/common/widgets/network_img_layer.dart @@ -106,6 +106,7 @@ class NetworkImgLayer extends StatelessWidget { } Widget placeholder(BuildContext context) { + int cacheWidth = width.cacheSize(context); return Container( width: width, height: height, @@ -127,7 +128,7 @@ class NetworkImgLayer extends StatelessWidget { : 'assets/images/loading.png', width: width, height: height, - cacheWidth: width.cacheSize(context), + cacheWidth: cacheWidth == 0 ? null : cacheWidth, // cacheHeight: height.cacheSize(context), ), ), diff --git a/lib/pages/common/reply_controller.dart b/lib/pages/common/reply_controller.dart index 9f4e9f8fb..14426e9a6 100644 --- a/lib/pages/common/reply_controller.dart +++ b/lib/pages/common/reply_controller.dart @@ -4,6 +4,7 @@ import 'package:PiliPalaX/models/common/reply_type.dart'; import 'package:PiliPalaX/pages/common/common_controller.dart'; import 'package:PiliPalaX/pages/video/detail/reply_new/reply_page.dart'; import 'package:PiliPalaX/utils/extension.dart'; +import 'package:PiliPalaX/utils/utils.dart'; import 'package:easy_debounce/easy_throttle.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -155,20 +156,18 @@ abstract class ReplyController extends CommonController { ), ) .then( - (value) { - // TODO: data cast - if (value != null && value['data'] != null) { + (res) { + if (res != null) { savedReplies[key] = null; - if (value['data'] is ReplyInfo) { - MainListReply response = - (loadingState.value as Success?)?.response ?? MainListReply(); - if (oid != null) { - response.replies.insert(0, value['data']); - } else { - response.replies[index].replies.add(value['data']); - } - loadingState.value = LoadingState.success(response); + ReplyInfo replyInfo = Utils.replyCast(res); + MainListReply response = + (loadingState.value as Success?)?.response ?? MainListReply(); + if (oid != null) { + response.replies.insert(0, replyInfo); + } else { + response.replies[index].replies.add(replyInfo); } + loadingState.value = LoadingState.success(response); } }, ); diff --git a/lib/pages/video/detail/reply_new/reply_page.dart b/lib/pages/video/detail/reply_new/reply_page.dart index 2760f6c04..0dcae4843 100644 --- a/lib/pages/video/detail/reply_new/reply_page.dart +++ b/lib/pages/video/detail/reply_new/reply_page.dart @@ -13,7 +13,6 @@ import 'package:get/get.dart'; import 'package:PiliPalaX/http/video.dart'; import 'package:PiliPalaX/models/common/reply_type.dart'; import 'package:PiliPalaX/models/video/reply/emote.dart'; -import 'package:PiliPalaX/models/video/reply/item.dart'; import 'package:PiliPalaX/pages/emote/index.dart'; import 'package:PiliPalaX/utils/feed_back.dart'; import 'package:PiliPalaX/pages/emote/view.dart'; @@ -517,9 +516,7 @@ class _ReplyPageState extends State ); if (result['status']) { SmartDialog.showToast(result['data']['success_toast']); - Get.back(result: { - 'data': ReplyItemModel.fromJson(result['data']['reply'], ''), - }); + Get.back(result: result['data']['reply']); } else { SmartDialog.showToast(result['msg']); } diff --git a/lib/pages/video/detail/reply_reply/view.dart b/lib/pages/video/detail/reply_reply/view.dart index 672d61896..89dbc76a4 100644 --- a/lib/pages/video/detail/reply_reply/view.dart +++ b/lib/pages/video/detail/reply_reply/view.dart @@ -3,6 +3,7 @@ import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart'; import 'package:PiliPalaX/http/loading_state.dart'; import 'package:PiliPalaX/pages/video/detail/reply/widgets/reply_item_grpc.dart'; import 'package:PiliPalaX/pages/video/detail/reply_new/reply_page.dart'; +import 'package:PiliPalaX/utils/utils.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:PiliPalaX/common/skeleton/video_reply.dart'; @@ -158,7 +159,7 @@ class _VideoReplyReplyPanelState extends State { replyType: widget.replyType, needDivider: false, onReply: () { - _onReply(firstFloor!); + _onReply(firstFloor!, -1); }, upMid: _videoReplyReplyController.upMid, ); @@ -237,7 +238,7 @@ class _VideoReplyReplyPanelState extends State { ), ); - void _onReply(ReplyInfo? item) { + void _onReply(ReplyInfo? item, int index) { dynamic oid = item?.oid.toInt(); dynamic root = item?.id.toInt(); dynamic parent = item?.id.toInt(); @@ -274,20 +275,16 @@ class _VideoReplyReplyPanelState extends State { }, ), ) - .then((value) { - // 完成评论,数据添加 // TODO: data cast - if (value != null && value['data'] != null) { + .then((res) { + if (res != null) { _savedReplies[key] = null; - if (value['data'] is ReplyInfo) { - List list = - _videoReplyReplyController.loadingState.value is Success - ? (_videoReplyReplyController.loadingState.value as Success) - .response - : []; - list.add(value['data']); - _videoReplyReplyController.loadingState.value = - LoadingState.success(list); - } + ReplyInfo replyInfo = Utils.replyCast(res); + List list = (_videoReplyReplyController.loadingState.value as Success?) + ?.response ?? + []; + list.insert(index + 1, replyInfo); + _videoReplyReplyController.loadingState.value = + LoadingState.success(list); } }); } @@ -320,11 +317,11 @@ class _VideoReplyReplyPanelState extends State { return ColoredBox( color: _videoReplyReplyController.colorAnimation?.value ?? Theme.of(Get.context!).colorScheme.onInverseSurface, - child: _replyItem(loadingState.response[index]), + child: _replyItem(loadingState.response[index], index), ); }, ) - : _replyItem(loadingState.response[index]); + : _replyItem(loadingState.response[index], index); } } else if (loadingState is Error) { return CustomScrollView( @@ -355,14 +352,14 @@ class _VideoReplyReplyPanelState extends State { } } - Widget _replyItem(replyItem) { + Widget _replyItem(replyItem, index) { return ReplyItemGrpc( replyItem: replyItem, replyLevel: widget.isDialogue ? '3' : '2', showReplyRow: false, replyType: widget.replyType, onReply: () { - _onReply(replyItem); + _onReply(replyItem, index); }, onDelete: (rpid, frpid) { List list = diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index d1ce53946..98f998092 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'dart:math'; +import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart'; import 'package:PiliPalaX/http/member.dart'; import 'package:PiliPalaX/http/search.dart'; import 'package:PiliPalaX/http/video.dart'; @@ -25,6 +26,27 @@ import 'package:url_launcher/url_launcher.dart'; class Utils { static final Random random = Random(); + static ReplyInfo replyCast(res) { + Map emote = res['content']['emote']; + emote.forEach((key, value) { + value['size'] = value['meta']['size']; + }); + return ReplyInfo.create() + ..mergeFromProto3Json( + res + ..['id'] = res['rpid'] + ..['member']['name'] = res['member']['uname'] + ..['member']['face'] = res['member']['avatar'] + ..['member']['level'] = res['member']['level_info']['current_level'] + ..['member']['vipStatus'] = res['member']['vip']['vipStatus'] + ..['member']['vipType'] = res['member']['vip']['vipType'] + ..['member']['officialVerifyType'] = + res['member']['official_verify']['type'] + ..['content']['emote'] = emote, + ignoreUnknownFields: true, + ); + } + static bool isDefault(int attr) { return (attr & 2) == 0; }