diff --git a/analysis_options.yaml b/analysis_options.yaml index 54694b68f..76b083962 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -72,5 +72,11 @@ linter: - use_truncating_division - use_string_buffers - unnecessary_statements + - unnecessary_nullable_for_final_variable_declarations + - tighten_type_of_initializing_formals + - prefer_void_to_null + - prefer_spread_collections + - unnecessary_to_list_in_spreads + - prefer_for_elements_to_map_fromIterable # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/lib/common/widgets/disabled_icon.dart b/lib/common/widgets/disabled_icon.dart index 328de9349..3f38bc222 100644 --- a/lib/common/widgets/disabled_icon.dart +++ b/lib/common/widgets/disabled_icon.dart @@ -20,20 +20,16 @@ class DisabledIcon extends SingleChildRenderObjectWidget { final StrokeCap strokeCap; final double lineLengthScale; + Icon? get _icon => child is Icon ? child as Icon : null; + @override RenderObject createRenderObject(BuildContext context) { late final iconTheme = IconTheme.of(context); + final icon = _icon; return RenderMaskedIcon( disable: disable, - iconSize: - iconSize ?? - (child is Icon ? (child as Icon).size : null) ?? - iconTheme.size ?? - 24.0, - color: - color ?? - (child is Icon ? (child as Icon).color : null) ?? - iconTheme.color!, + iconSize: iconSize ?? icon?.size ?? iconTheme.size ?? 24.0, + color: color ?? icon?.color ?? iconTheme.color!, strokeCap: strokeCap, lineLengthScale: lineLengthScale, ); @@ -42,17 +38,11 @@ class DisabledIcon extends SingleChildRenderObjectWidget { @override void updateRenderObject(BuildContext context, RenderMaskedIcon renderObject) { late final iconTheme = IconTheme.of(context); + final icon = _icon; renderObject ..disable = disable - ..iconSize = - iconSize ?? - (child is Icon ? (child as Icon).size : null) ?? - iconTheme.size ?? - 24.0 - ..color = - color ?? - (child is Icon ? (child as Icon).color : null) ?? - iconTheme.color! + ..iconSize = iconSize ?? icon?.size ?? iconTheme.size ?? 24.0 + ..color = color ?? icon?.color ?? iconTheme.color! ..strokeCap = strokeCap ..lineLengthScale = lineLengthScale; } diff --git a/lib/common/widgets/only_layout_widget.dart b/lib/common/widgets/only_layout_widget.dart index 491b7ba2d..d78a46e15 100644 --- a/lib/common/widgets/only_layout_widget.dart +++ b/lib/common/widgets/only_layout_widget.dart @@ -43,42 +43,3 @@ class NoRenderLayoutBox extends RenderProxyBox { @override void paint(PaintingContext context, Offset offset) {} } - -class LayoutSizeWidget extends SingleChildRenderObjectWidget { - const LayoutSizeWidget({ - super.key, - super.child, - required this.onPerformLayout, - }); - - final LayoutCallback onPerformLayout; - - @override - RenderObject createRenderObject(BuildContext context) => - RenderLayoutBox(onPerformLayout: onPerformLayout); - - @override - void updateRenderObject( - BuildContext context, - RenderLayoutBox renderObject, - ) { - super.updateRenderObject(context, renderObject); - renderObject.onPerformLayout = onPerformLayout; - } -} - -class RenderLayoutBox extends RenderProxyBox { - RenderLayoutBox({required this.onPerformLayout}); - - LayoutCallback onPerformLayout; - - Size? _size; - - @override - void performLayout() { - super.performLayout(); - if (_size != size) { - onPerformLayout(_size = size); - } - } -} diff --git a/lib/common/widgets/sliver_wrap.dart b/lib/common/widgets/sliver_wrap.dart index a2abcd3e6..492a8b8fd 100644 --- a/lib/common/widgets/sliver_wrap.dart +++ b/lib/common/widgets/sliver_wrap.dart @@ -96,7 +96,6 @@ class RenderSliverFixedWrap extends RenderSliverMultiBoxAdaptor { set runSpacing(double value) { if (_runSpacing == value) return; _runSpacing = value; - markRowsDirty(); markNeedsLayout(); } @@ -168,20 +167,20 @@ class RenderSliverFixedWrap extends RenderSliverMultiBoxAdaptor { } } - bool _buildNextRow(int start, BoxConstraints childConstraints) { + bool _buildNextRow(int start, BoxConstraints constraints) { final int childCount = childManager.childCount; if (start >= childCount) { return false; } - final crossAxisExtent = constraints.crossAxisExtent; + final crossAxisExtent = this.constraints.crossAxisExtent; final List widths = []; int idx = start; RenderBox? child; for (var totalWidth = -_spacing; idx < childCount; idx++) { - child = _getOrCreateChildAtIndex(idx, childConstraints, child); + child = _getOrCreateChildAtIndex(idx, constraints, child); final childWidth = _childCrossExtent(child); totalWidth += childWidth + _spacing; @@ -215,24 +214,20 @@ class RenderSliverFixedWrap extends RenderSliverMultiBoxAdaptor { final firstNeededRow = math.max(0, firstCacheOffset ~/ rowHeight); final lastNeededRow = math.max(0, lastCacheOffset ~/ rowHeight); + final childConstraints = constraints.toFixedConstraints(_mainAxisExtent); + if (firstChild == null) { if (!addInitialChild()) { geometry = SliverGeometry.zero; childManager.didFinishLayout(); return; } - firstChild!.layout( - constraints.toFixedConstraints(_mainAxisExtent), - parentUsesSize: true, - ); + firstChild!.layout(childConstraints, parentUsesSize: true); } while (_rows.length <= lastNeededRow) { final int startIndex = _rows.isEmpty ? 0 : _rows.last.endIndex + 1; - if (!_buildNextRow( - startIndex, - constraints.toFixedConstraints(_mainAxisExtent), - )) { + if (!_buildNextRow(startIndex, childConstraints)) { break; } } @@ -256,11 +251,7 @@ class RenderSliverFixedWrap extends RenderSliverMultiBoxAdaptor { final rowStartOffset = r * rowHeight; double crossOffset = 0.0; for (var i = row.startIndex; i <= row.endIndex; i++) { - child = _getOrCreateChildAtIndex( - i, - constraints.toFixedConstraints(_mainAxisExtent), - child, - ); + child = _getOrCreateChildAtIndex(i, childConstraints, child); (child.parentData as SliverWrapParentData) ..layoutOffset = rowStartOffset ..crossAxisOffset = crossOffset; diff --git a/lib/http/danmaku.dart b/lib/http/danmaku.dart index abf6d71de..2d5b9efbf 100644 --- a/lib/http/danmaku.dart +++ b/lib/http/danmaku.dart @@ -60,7 +60,7 @@ abstract final class DanmakuHttp { } } - static Future> danmakuLike({ + static Future> danmakuLike({ required bool isLike, required int cid, required int id, @@ -89,7 +89,7 @@ abstract final class DanmakuHttp { } } - static Future> danmakuReport({ + static Future> danmakuReport({ required int reason, required int cid, required int id, diff --git a/lib/http/danmaku_block.dart b/lib/http/danmaku_block.dart index f130940c4..c6bf1c68e 100644 --- a/lib/http/danmaku_block.dart +++ b/lib/http/danmaku_block.dart @@ -15,7 +15,7 @@ abstract final class DanmakuFilterHttp { } } - static Future> danmakuFilterDel({required int ids}) async { + static Future> danmakuFilterDel({required int ids}) async { final res = await Request().post( Api.danmakuFilterDel, data: { diff --git a/lib/http/dynamics.dart b/lib/http/dynamics.dart index abeedb71f..fac9b1aeb 100644 --- a/lib/http/dynamics.dart +++ b/lib/http/dynamics.dart @@ -127,7 +127,7 @@ abstract final class DynamicsHttp { // } // 动态点赞 - static Future> thumbDynamic({ + static Future> thumbDynamic({ required String? dynamicId, required int? up, }) async { @@ -275,7 +275,7 @@ abstract final class DynamicsHttp { } } - static Future> setTop({ + static Future> setTop({ required Object dynamicId, }) async { final res = await Request().post( @@ -294,7 +294,7 @@ abstract final class DynamicsHttp { } } - static Future> rmTop({ + static Future> rmTop({ required Object dynamicId, }) async { final res = await Request().post( @@ -672,7 +672,7 @@ abstract final class DynamicsHttp { } } - static Future> dynPrivatePubSetting({ + static Future> dynPrivatePubSetting({ required Object dynId, int? dynType, required String action, @@ -699,7 +699,7 @@ abstract final class DynamicsHttp { } } - static Future> editDyn({ + static Future> editDyn({ required Object dynId, Object? repostDynId, dynamic rawText, diff --git a/lib/http/fav.dart b/lib/http/fav.dart index 348a3adff..1d806a4d2 100644 --- a/lib/http/fav.dart +++ b/lib/http/fav.dart @@ -18,7 +18,7 @@ import 'package:PiliPlus/utils/app_sign.dart'; import 'package:dio/dio.dart'; abstract final class FavHttp { - static Future> favFavFolder(Object mediaId) async { + static Future> favFavFolder(Object mediaId) async { final res = await Request().post( Api.favFavFolder, data: { @@ -34,7 +34,7 @@ abstract final class FavHttp { } } - static Future> unfavFavFolder(Object mediaId) async { + static Future> unfavFavFolder(Object mediaId) async { final res = await Request().post( Api.unfavFavFolder, data: { @@ -79,7 +79,7 @@ abstract final class FavHttp { } // 取消订阅 - static Future> cancelSub({ + static Future> cancelSub({ required int id, required int type, }) async { @@ -148,7 +148,7 @@ abstract final class FavHttp { } } - static Future> addFavPugv(Object seasonId) async { + static Future> addFavPugv(Object seasonId) async { final res = await Request().post( Api.addFavPugv, data: { @@ -164,7 +164,7 @@ abstract final class FavHttp { } } - static Future> delFavPugv(Object seasonId) async { + static Future> delFavPugv(Object seasonId) async { final res = await Request().post( Api.delFavPugv, data: { @@ -198,7 +198,7 @@ abstract final class FavHttp { } } - static Future> addFavTopic(Object topicId) async { + static Future> addFavTopic(Object topicId) async { final res = await Request().post( Api.addFavTopic, data: { @@ -214,7 +214,7 @@ abstract final class FavHttp { } } - static Future> delFavTopic(Object topicId) async { + static Future> delFavTopic(Object topicId) async { final res = await Request().post( Api.delFavTopic, data: { @@ -230,7 +230,7 @@ abstract final class FavHttp { } } - static Future> likeTopic( + static Future> likeTopic( Object topicId, bool isLike, ) async { @@ -269,7 +269,7 @@ abstract final class FavHttp { } } - static Future> addFavArticle({ + static Future> addFavArticle({ required Object id, }) async { final res = await Request().post( @@ -289,7 +289,7 @@ abstract final class FavHttp { } } - static Future> delFavArticle({ + static Future> delFavArticle({ required Object id, }) async { final res = await Request().post( @@ -351,7 +351,7 @@ abstract final class FavHttp { } } - static Future> delNote({ + static Future> delNote({ required bool isPublish, required String noteIds, }) async { @@ -415,7 +415,7 @@ abstract final class FavHttp { } } - static Future> sortFavFolder({ + static Future> sortFavFolder({ required String sort, }) async { Map data = { @@ -437,7 +437,7 @@ abstract final class FavHttp { } } - static Future> sortFav({ + static Future> sortFav({ required Object mediaId, required String sort, }) async { @@ -461,7 +461,7 @@ abstract final class FavHttp { } } - static Future> cleanFav({ + static Future> cleanFav({ required Object mediaId, }) async { final res = await Request().post( @@ -482,7 +482,7 @@ abstract final class FavHttp { } } - static Future> deleteFolder({ + static Future> deleteFolder({ required String mediaIds, }) async { final res = await Request().post( @@ -548,7 +548,7 @@ abstract final class FavHttp { } } - static Future> seasonFav({ + static Future> seasonFav({ required bool isFav, required dynamic seasonId, }) async { @@ -605,7 +605,7 @@ abstract final class FavHttp { } } - static Future> communityAction({ + static Future> communityAction({ required Object opusId, required Object action, }) async { @@ -630,7 +630,7 @@ abstract final class FavHttp { } // (取消)收藏 - static Future> favVideo({ + static Future> favVideo({ required String resources, String? addIds, String? delIds, @@ -653,7 +653,7 @@ abstract final class FavHttp { } // (取消)收藏 - static Future> unfavAll({ + static Future> unfavAll({ required Object rid, required Object type, }) async { @@ -673,7 +673,7 @@ abstract final class FavHttp { } } - static Future> copyOrMoveFav({ + static Future> copyOrMoveFav({ required bool isCopy, required bool isFav, required dynamic srcMediaId, diff --git a/lib/http/live.dart b/lib/http/live.dart index 2871d6d98..16fe87e4d 100644 --- a/lib/http/live.dart +++ b/lib/http/live.dart @@ -33,7 +33,7 @@ import 'package:dio/dio.dart'; abstract final class LiveHttp { static Account get recommend => Accounts.get(AccountType.recommend); - static Future> sendLiveMsg({ + static Future> sendLiveMsg({ required Object roomId, required Object msg, Object? dmType, @@ -385,7 +385,7 @@ abstract final class LiveHttp { } } - static Future> setLiveFavTag({ + static Future> setLiveFavTag({ required String ids, }) async { final data = { @@ -505,7 +505,7 @@ abstract final class LiveHttp { } } - static Future> liveSetSilent({ + static Future> liveSetSilent({ required String type, required int level, }) async { @@ -527,7 +527,7 @@ abstract final class LiveHttp { } } - static Future> addShieldKeyword({ + static Future> addShieldKeyword({ required String keyword, }) async { final csrf = Accounts.main.csrf; @@ -547,7 +547,7 @@ abstract final class LiveHttp { } } - static Future> delShieldKeyword({ + static Future> delShieldKeyword({ required String keyword, }) async { final csrf = Accounts.main.csrf; @@ -591,7 +591,7 @@ abstract final class LiveHttp { } } - static Future> liveLikeReport({ + static Future> liveLikeReport({ required int clickTime, required Object roomId, required Object uid, @@ -637,7 +637,7 @@ abstract final class LiveHttp { } } - static Future> liveDmReport({ + static Future> liveDmReport({ required int roomId, required Object mid, required String msg, @@ -707,7 +707,7 @@ abstract final class LiveHttp { } } - static Future> superChatReport({ + static Future> superChatReport({ required int id, required Object roomId, required Object uid, diff --git a/lib/http/member.dart b/lib/http/member.dart index 50936fe2e..dd4cc008f 100644 --- a/lib/http/member.dart +++ b/lib/http/member.dart @@ -482,7 +482,7 @@ abstract final class MemberHttp { } } - static Future> specialAction({ + static Future> specialAction({ int? fid, bool isAdd = true, }) async { @@ -502,7 +502,7 @@ abstract final class MemberHttp { } // 设置分组 - static Future> addUsers(String fids, String tagids) async { + static Future> addUsers(String fids, String tagids) async { final res = await Request().post( Api.addUsers, queryParameters: { @@ -555,7 +555,7 @@ abstract final class MemberHttp { } } - static Future> createFollowTag(Object tagName) async { + static Future> createFollowTag(Object tagName) async { final res = await Request().post( Api.createFollowTag, queryParameters: { @@ -575,7 +575,7 @@ abstract final class MemberHttp { } } - static Future> updateFollowTag( + static Future> updateFollowTag( Object tagid, Object name, ) async { @@ -599,7 +599,7 @@ abstract final class MemberHttp { } } - static Future> delFollowTag(Object tagid) async { + static Future> delFollowTag(Object tagid) async { final res = await Request().post( Api.delFollowTag, queryParameters: { diff --git a/lib/http/msg.dart b/lib/http/msg.dart index e6d9138a4..b52009ed3 100644 --- a/lib/http/msg.dart +++ b/lib/http/msg.dart @@ -18,7 +18,6 @@ import 'package:PiliPlus/models_new/upload_bfs/data.dart'; import 'package:PiliPlus/utils/accounts.dart'; import 'package:PiliPlus/utils/wbi_sign.dart'; import 'package:dio/dio.dart'; -import 'package:uuid/v4.dart'; abstract final class MsgHttp { static Future> msgFeedReplyMe({ @@ -136,7 +135,7 @@ abstract final class MsgHttp { } } - static Future> msgSysUpdateCursor(int cursor) async { + static Future> msgSysUpdateCursor(int cursor) async { String csrf = Accounts.main.csrf; final res = await Request().get( Api.msgSysUpdateCursor, @@ -196,7 +195,7 @@ abstract final class MsgHttp { } } - static Future> createTextDynamic( + static Future> createTextDynamic( Object content, ) async { String csrf = Accounts.main.csrf; @@ -220,7 +219,7 @@ abstract final class MsgHttp { } } - static Future> removeDynamic({ + static Future> removeDynamic({ required Object dynIdStr, Object? dynType, Object? ridStr, @@ -244,7 +243,7 @@ abstract final class MsgHttp { } } - static Future> removeMsg( + static Future> removeMsg( Object talkerId, ) async { String csrf = Accounts.main.csrf; @@ -268,7 +267,7 @@ abstract final class MsgHttp { } } - static Future> delMsgfeed( + static Future> delMsgfeed( int tp, dynamic id, ) async { @@ -292,7 +291,7 @@ abstract final class MsgHttp { } } - static Future> delSysMsg( + static Future> delSysMsg( Object id, ) async { String csrf = Accounts.main.csrf; @@ -317,7 +316,7 @@ abstract final class MsgHttp { } } - static Future> setTop({ + static Future> setTop({ required Object talkerId, required int opType, }) async { @@ -344,7 +343,7 @@ abstract final class MsgHttp { } // 消息标记已读 - static Future> ackSessionMsg({ + static Future> ackSessionMsg({ required int talkerId, required int ackSeqno, }) async { @@ -370,60 +369,60 @@ abstract final class MsgHttp { } } - // 发送私信 - static Future> sendMsg({ - int? senderUid, - int? receiverId, - int? msgType, - dynamic content, - }) async { - String csrf = Accounts.main.csrf; - final devId = getDevId(); - final data = { - 'msg': { - 'sender_uid': senderUid, - 'receiver_id': receiverId, - 'receiver_type': 1, - 'msg_type': msgType ?? 1, - 'msg_status': 0, - 'dev_id': devId, - 'timestamp': DateTime.now().millisecondsSinceEpoch ~/ 1000, - 'new_face_version': 1, - 'content': content, - }, - 'from_firework': 0, - 'build': 0, - 'mobi_app': 'web', - 'csrf_token': csrf, - 'csrf': csrf, - }; - Map params = await WbiSign.makSign(data); - final res = await Request().post( - Api.sendMsg, - queryParameters: { - 'w_sender_uid': senderUid, - 'w_receiver_id': receiverId, - 'w_dev_id': devId, - 'w_rid': params['w_rid'], - 'wts': params['wts'], - }, - data: data, - options: Options( - contentType: Headers.formUrlEncodedContentType, - ), - ); - if (res.data['code'] == 0) { - return const Success(null); - } else { - return Error(res.data['message']); - } - } + // // 发送私信 + // static Future> sendMsg({ + // required int senderUid, + // required int receiverId, + // int? msgType, + // dynamic content, + // }) async { + // String csrf = Accounts.main.csrf; + // final devId = getDevId(); + // final data = { + // 'msg': { + // 'sender_uid': senderUid, + // 'receiver_id': receiverId, + // 'receiver_type': 1, + // 'msg_type': msgType ?? 1, + // 'msg_status': 0, + // 'dev_id': devId, + // 'timestamp': DateTime.now().millisecondsSinceEpoch ~/ 1000, + // 'new_face_version': 1, + // 'content': content, + // }, + // 'from_firework': 0, + // 'build': 0, + // 'mobi_app': 'web', + // 'csrf_token': csrf, + // 'csrf': csrf, + // }; + // Map params = await WbiSign.makSign(data); + // final res = await Request().post( + // Api.sendMsg, + // queryParameters: { + // 'w_sender_uid': senderUid, + // 'w_receiver_id': receiverId, + // 'w_dev_id': devId, + // 'w_rid': params['w_rid'], + // 'wts': params['wts'], + // }, + // data: data, + // options: Options( + // contentType: Headers.formUrlEncodedContentType, + // ), + // ); + // if (res.data['code'] == 0) { + // return const Success(null); + // } else { + // return Error(res.data['message']); + // } + // } - static String getDevId() { - return const UuidV4().generate(); - } + // static String getDevId() { + // return const UuidV4().generate(); + // } - static Future> msgSetNotice({ + static Future> msgSetNotice({ required Object id, required int noticeState, }) async { @@ -451,7 +450,7 @@ abstract final class MsgHttp { } } - static Future> setMsgDnd({ + static Future> setMsgDnd({ required Object uid, required int setting, required dndUid, @@ -477,7 +476,7 @@ abstract final class MsgHttp { } } - static Future> setPushSs({ + static Future> setPushSs({ required int setting, required talkerUid, }) async { @@ -606,7 +605,7 @@ abstract final class MsgHttp { } } - static Future> imMsgReport({ + static Future> imMsgReport({ required int accusedUid, required int reasonType, required String reasonDesc, diff --git a/lib/http/music.dart b/lib/http/music.dart index 74d37d94c..4a33fadb3 100644 --- a/lib/http/music.dart +++ b/lib/http/music.dart @@ -23,7 +23,7 @@ abstract final class MusicHttp { } } - static Future> wishUpdate( + static Future> wishUpdate( String musicId, bool hasLike, ) async { diff --git a/lib/http/pgc.dart b/lib/http/pgc.dart index 7ed6ae3f0..1fe0f54fa 100644 --- a/lib/http/pgc.dart +++ b/lib/http/pgc.dart @@ -133,7 +133,7 @@ abstract final class PgcHttp { } } - static Future> pgcReviewLike({ + static Future> pgcReviewLike({ required Object mediaId, required Object reviewId, }) async { @@ -154,7 +154,7 @@ abstract final class PgcHttp { } } - static Future> pgcReviewDislike({ + static Future> pgcReviewDislike({ required Object mediaId, required Object reviewId, }) async { @@ -175,7 +175,7 @@ abstract final class PgcHttp { } } - static Future> pgcReviewPost({ + static Future> pgcReviewPost({ required Object mediaId, required int score, required String content, @@ -199,7 +199,7 @@ abstract final class PgcHttp { } } - static Future> pgcReviewMod({ + static Future> pgcReviewMod({ required Object mediaId, required int score, required String content, @@ -223,7 +223,7 @@ abstract final class PgcHttp { } } - static Future> pgcReviewDel({ + static Future> pgcReviewDel({ required Object mediaId, required Object reviewId, }) async { diff --git a/lib/http/reply.dart b/lib/http/reply.dart index 44c0b38fb..db9bc1009 100644 --- a/lib/http/reply.dart +++ b/lib/http/reply.dart @@ -88,7 +88,7 @@ abstract final class ReplyHttp { } } - static Future> hateReply({ + static Future> hateReply({ required int type, required int action, required int oid, @@ -113,7 +113,7 @@ abstract final class ReplyHttp { } // 评论点赞 - static Future> likeReply({ + static Future> likeReply({ required int type, required int oid, required int rpid, @@ -154,7 +154,7 @@ abstract final class ReplyHttp { } } - static Future> replyTop({ + static Future> replyTop({ required Object oid, required Object type, required Object rpid, @@ -178,7 +178,7 @@ abstract final class ReplyHttp { } } - static Future> report({ + static Future> report({ required Object rpid, required Object oid, required int reasonType, @@ -232,7 +232,7 @@ abstract final class ReplyHttp { } } - static Future> replySubjectModify({ + static Future> replySubjectModify({ required int oid, required int type, required int action, diff --git a/lib/http/sponsor_block.dart b/lib/http/sponsor_block.dart index a73760f38..553f2f051 100644 --- a/lib/http/sponsor_block.dart +++ b/lib/http/sponsor_block.dart @@ -74,7 +74,7 @@ abstract final class SponsorBlock { return getErrMsg(res); } - static Future> voteOnSponsorTime({ + static Future> voteOnSponsorTime({ required String uuid, int? type, SegmentType? category, @@ -93,7 +93,7 @@ abstract final class SponsorBlock { return res.statusCode == 200 ? const Success(null) : getErrMsg(res); } - static Future> viewedVideoSponsorTime(String uuid) async { + static Future> viewedVideoSponsorTime(String uuid) async { final res = await Request().post( _api(SponsorBlockApi.viewedVideoSponsorTime), data: {'UUID': uuid}, @@ -102,7 +102,7 @@ abstract final class SponsorBlock { return res.statusCode == 200 ? const Success(null) : getErrMsg(res); } - static Future> uptimeStatus() async { + static Future> uptimeStatus() async { final res = await Request().get( _api(SponsorBlockApi.uptimeStatus), options: options, diff --git a/lib/http/user.dart b/lib/http/user.dart index a22331252..5c10958d9 100644 --- a/lib/http/user.dart +++ b/lib/http/user.dart @@ -105,7 +105,7 @@ abstract final class UserHttp { } // 暂停观看历史 - static Future> pauseHistory( + static Future> pauseHistory( bool switchStatus, { Account? account, }) async { @@ -144,7 +144,7 @@ abstract final class UserHttp { } // 清空历史记录 - static Future> clearHistory({Account? account}) async { + static Future> clearHistory({Account? account}) async { account ??= Accounts.history; final res = await Request().post( Api.clearHistory, @@ -165,7 +165,7 @@ abstract final class UserHttp { } // 稍后再看 - static Future> toViewLater({ + static Future> toViewLater({ String? bvid, Object? aid, }) async { @@ -189,7 +189,7 @@ abstract final class UserHttp { } // 移除已观看 - static Future> toViewDel({required String aids}) async { + static Future> toViewDel({required String aids}) async { final Map params = { 'csrf': Accounts.main.csrf, 'resources': aids, @@ -228,7 +228,7 @@ abstract final class UserHttp { // } // 清空稍后再看 // clean_type: null->all, 1->invalid, 2->viewed - static Future> toViewClear([int? cleanType]) async { + static Future> toViewClear([int? cleanType]) async { final res = await Request().post( Api.toViewClear, data: { @@ -245,7 +245,7 @@ abstract final class UserHttp { } // 删除历史记录 - static Future> delHistory( + static Future> delHistory( String kid, { Account? account, }) async { @@ -390,7 +390,7 @@ abstract final class UserHttp { } } - static Future> dynamicReport({ + static Future> dynamicReport({ required Object mid, required Object dynId, required int reasonType, @@ -430,7 +430,7 @@ abstract final class UserHttp { } } - static Future> spaceSettingMod(Map data) async { + static Future> spaceSettingMod(Map data) async { final res = await Request().post( Api.spaceSettingMod, queryParameters: { @@ -446,7 +446,7 @@ abstract final class UserHttp { } } - static Future> vipExpAdd() async { + static Future> vipExpAdd() async { final res = await Request().post( Api.vipExpAdd, queryParameters: { diff --git a/lib/http/video.dart b/lib/http/video.dart index bf1d62769..76ad7e8d4 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -345,7 +345,7 @@ abstract final class VideoHttp { } // 投币 - static Future> coinVideo({ + static Future> coinVideo({ required String bvid, required int multiply, int selectLike = 0, @@ -443,7 +443,7 @@ abstract final class VideoHttp { } // (取消)点踩 - static Future> dislikeVideo({ + static Future> dislikeVideo({ required String bvid, required bool type, }) async { @@ -466,7 +466,7 @@ abstract final class VideoHttp { } // 推送不感兴趣反馈 - static Future> feedDislike({ + static Future> feedDislike({ required String goto, required int id, int? reasonId, @@ -495,7 +495,7 @@ abstract final class VideoHttp { } // 推送不感兴趣取消 - static Future> feedDislikeCancel({ + static Future> feedDislikeCancel({ required String goto, required int id, int? reasonId, @@ -578,7 +578,7 @@ abstract final class VideoHttp { } } - static Future> replyDel({ + static Future> replyDel({ required int type, //replyType required int oid, required int rpid, @@ -602,7 +602,7 @@ abstract final class VideoHttp { } // 操作用户关系 - static Future> relationMod({ + static Future> relationMod({ required int mid, required int act, required int reSrc, diff --git a/lib/models/video/play/url.dart b/lib/models/video/play/url.dart index d728e313c..7bfab6f01 100644 --- a/lib/models/video/play/url.dart +++ b/lib/models/video/play/url.dart @@ -163,19 +163,15 @@ class Dash { video = (json['video'] as List?) ?.map((e) => VideoItem.fromJson(e)) .toList(); - audio = (json['audio'] as List?) - ?.map((e) => AudioItem.fromJson(e)) - .toList(); - if (json['dolby']?['audio'] case List list) { - (audio ??= []).insertAll( - 0, - list.map((e) => AudioItem.fromJson(e)), - ); - } - final flacAudio = json['flac']?['audio']; - if (flacAudio != null) { - (audio ??= []).insert(0, AudioItem.fromJson(flacAudio)); - } + final audio = [ + if (json['flac']?['audio'] case Map flac) + AudioItem.fromJson(flac), + if (json['dolby']?['audio'] case List list) + ...list.map((e) => AudioItem.fromJson(e)), + if (json['audio'] case List list) + ...list.map((e) => AudioItem.fromJson(e)), + ]; + this.audio = audio.isEmpty ? null : audio; } } diff --git a/lib/models_new/space/space/top.dart b/lib/models_new/space/space/top.dart index a378bd3b5..8bbc252e0 100644 --- a/lib/models_new/space/space/top.dart +++ b/lib/models_new/space/space/top.dart @@ -5,36 +5,46 @@ class Top { Top({this.imgUrls}); + @pragma('vm:notify-debugger-on-exception') Top.fromJson(Map json) { try { - final list = json['result'] as List?; - if (list != null && list.isNotEmpty) { - imgUrls = list.map((e) => TopImage.fromJson(e)).toList(); - } + imgUrls = (json['result'] as List?) + ?.map((e) => TopImage.fromJson(e)) + .toList(); } catch (_) {} } } class TopImage { - late final String cover; + String? _defaultImage; + late final String fullCover; + String get header => _defaultImage ?? fullCover; late final double dy; + @pragma('vm:notify-debugger-on-exception') TopImage.fromJson(Map json) { - cover = - noneNullOrEmptyString(json['item']?['image']?['default_image']) ?? - json['cover']; + _defaultImage = noneNullOrEmptyString( + json['item']['image']?['default_image'], + ); + fullCover = json['cover']; + double dy = 0; try { final Map image = json['item']['image'] ?? json['item']['animation']; - final num halfHeight = (image['height'] as num) / 2; - final List location = (image['location'] as String) - .split('-') - .map(num.parse) - .toList(); - final start = location[1]; - final end = location[2]; - dy = (start + (end - start) / 2 - halfHeight) / halfHeight; - } catch (_) { - dy = 0.0; - } + if (image['location'] case String locStr when (locStr.isNotEmpty)) { + final location = locStr + .split('-') + .skip(1) + .take(2) + .map(num.parse) + .toList(); + if (location.length == 2) { + final num height = image['height']; + final start = location[0]; + final end = location[1]; + dy = (start + end) / height - 1; + } + } + } catch (_) {} + this.dy = dy; } } diff --git a/lib/pages/danmaku/controller.dart b/lib/pages/danmaku/controller.dart index bfc60217a..254d36d8c 100644 --- a/lib/pages/danmaku/controller.dart +++ b/lib/pages/danmaku/controller.dart @@ -6,7 +6,6 @@ import 'package:PiliPlus/grpc/dm.dart'; import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/plugin/pl_player/controller.dart'; import 'package:PiliPlus/plugin/pl_player/models/data_source.dart'; -import 'package:PiliPlus/plugin/pl_player/utils/danmaku_options.dart'; import 'package:PiliPlus/utils/accounts.dart'; import 'package:PiliPlus/utils/path_utils.dart'; import 'package:PiliPlus/utils/utils.dart'; @@ -68,8 +67,8 @@ class PlDanmakuController { if (elems.isEmpty) return; final uniques = HashMap(); - final shouldFilter = _plPlayerController.filters.count != 0; - final danmakuWeight = DanmakuOptions.danmakuWeight; + final filters = _plPlayerController.filters; + final shouldFilter = filters.count != 0; for (final element in elems) { if (_isLogin) { element.isSelf = element.midHash == _plPlayerController.midHash; @@ -86,8 +85,7 @@ class PlDanmakuController { } } - if (element.weight < danmakuWeight || - (shouldFilter && _plPlayerController.filters.remove(element))) { + if (shouldFilter && filters.remove(element)) { continue; } } diff --git a/lib/pages/member/view.dart b/lib/pages/member/view.dart index 9d22d3154..cadd6822f 100644 --- a/lib/pages/member/view.dart +++ b/lib/pages/member/view.dart @@ -40,7 +40,8 @@ class _MemberPageState extends State { late final String _heroTag; late final MemberController _userController; PageController? _headerController; - PageController get headerController => _headerController ??= PageController(); + PageController getHeaderController() => + _headerController ??= PageController(); @override void initState() { @@ -367,7 +368,7 @@ class _MemberPageState extends State { onFollow: () => _userController.onFollow(context), live: _userController.live, silence: _userController.silence, - headerControllerBuilder: () => headerController, + headerControllerBuilder: getHeaderController, ), ), ); diff --git a/lib/pages/member/widget/user_info_card.dart b/lib/pages/member/widget/user_info_card.dart index 5593d0a61..e9d4bf786 100644 --- a/lib/pages/member/widget/user_info_card.dart +++ b/lib/pages/member/widget/user_info_card.dart @@ -458,7 +458,7 @@ class UserInfoCard extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ HeaderLayoutWidget( - header: imgUrls != null + header: imgUrls != null && imgUrls.isNotEmpty ? _buildCollectionHeader(context, scheme, isLight, imgUrls, width) : _buildHeader( context, @@ -491,12 +491,15 @@ class UserInfoCard extends StatelessWidget { double width, ) { if (imgUrls.length == 1) { + final img = imgUrls.first; return _buildHeader( context, isLight, width, - imgUrls.single.cover, + img.header, filter: false, + fullCover: img.fullCover, + alignment: Alignment(0.0, img.dy), ); } final controller = headerControllerBuilder(); @@ -505,7 +508,7 @@ class UserInfoCard extends StatelessWidget { behavior: .opaque, onTap: () => PageUtils.imageView( initialPage: controller.page?.round() ?? 0, - imgList: imgUrls.map((e) => SourceModel(url: e.cover)).toList(), + imgList: imgUrls.map((e) => SourceModel(url: e.fullCover)).toList(), onPageChanged: controller.jumpToPage, ), child: Stack( @@ -520,14 +523,14 @@ class UserInfoCard extends StatelessWidget { itemBuilder: (context, index) { final img = imgUrls[index]; return fromHero( - tag: img.cover, + tag: img.fullCover, child: CachedNetworkImage( fit: .cover, alignment: Alignment(0.0, img.dy), height: kHeaderHeight, width: width, memCacheWidth: memCacheWidth, - imageUrl: ImageUtils.thumbnailUrl(img.cover), + imageUrl: ImageUtils.thumbnailUrl(img.header), fadeInDuration: const Duration(milliseconds: 120), fadeOutDuration: const Duration(milliseconds: 120), placeholder: (_, _) => @@ -557,14 +560,18 @@ class UserInfoCard extends StatelessWidget { double width, String imgUrl, { bool filter = true, + String? fullCover, + Alignment alignment = .center, }) { + final img = fullCover ?? imgUrl; return GestureDetector( behavior: .opaque, - onTap: () => PageUtils.imageView(imgList: [SourceModel(url: imgUrl)]), + onTap: () => PageUtils.imageView(imgList: [SourceModel(url: img)]), child: fromHero( - tag: imgUrl, + tag: img, child: CachedNetworkImage( fit: .cover, + alignment: alignment, height: kHeaderHeight, width: width, memCacheWidth: width.cacheSize(context), @@ -760,7 +767,8 @@ class _HeaderIndicatorState extends State { } void _updateProgress() { - _progress = ((widget.pageController.page ?? 0) + 1) / widget.length; + _progress = (widget.pageController.page ?? 0) / (widget.length - 1); + assert(_progress.isFinite && 0 <= _progress && _progress <= 1); } @override diff --git a/lib/pages/save_panel/view.dart b/lib/pages/save_panel/view.dart index 2d8c121e2..71a7cf596 100644 --- a/lib/pages/save_panel/view.dart +++ b/lib/pages/save_panel/view.dart @@ -1,6 +1,3 @@ -import 'dart:typed_data'; -import 'dart:ui'; - import 'package:PiliPlus/common/constants.dart'; import 'package:PiliPlus/common/widgets/button/icon_button.dart'; import 'package:PiliPlus/common/widgets/image/network_img_layer.dart'; @@ -292,14 +289,15 @@ class _SavePanelState extends State { } SmartDialog.showLoading(); try { - RenderRepaintBoundary boundary = + final boundary = boundaryKey.currentContext!.findRenderObject() as RenderRepaintBoundary; final image = await boundary.toImage(pixelRatio: 3); - ByteData? byteData = await image.toByteData(format: ImageByteFormat.png); - Uint8List pngBytes = byteData!.buffer.asUint8List(); - String picName = - "${Constants.appName}_${DateFormat('yyyyMMddHHmmss').format(DateTime.now())}"; + final byteData = await image.toByteData(format: .png); + image.dispose(); + final pngBytes = byteData!.buffer.asUint8List(); + final picName = + "${Constants.appName}_${itemType}_${DateFormat('yyyyMMddHHmmss').format(DateTime.now())}"; if (isShare) { Get.back(); SmartDialog.dismiss(); @@ -350,8 +348,7 @@ class _SavePanelState extends State { top: 12 + padding.top, bottom: 80 + padding.bottom, ), - child: GestureDetector( - onTap: () {}, + child: Listener( child: Container( width: maxWidth, padding: const EdgeInsets.symmetric(horizontal: 12), @@ -361,7 +358,7 @@ class _SavePanelState extends State { clipBehavior: Clip.hardEdge, decoration: BoxDecoration( color: theme.colorScheme.surface, - borderRadius: const BorderRadius.all(Radius.circular(12)), + borderRadius: const .all(.circular(12)), ), child: AnimatedSize( curve: Curves.easeInOut, @@ -393,40 +390,33 @@ class _SavePanelState extends State { Container( height: 81, clipBehavior: Clip.hardEdge, - margin: const EdgeInsets.symmetric( - horizontal: 12, - ), - padding: const EdgeInsets.all(8), + margin: const .symmetric(horizontal: 12), + padding: const .all(8), decoration: BoxDecoration( color: theme.colorScheme.onInverseSurface, - borderRadius: const BorderRadius.all( - Radius.circular(8), - ), + borderRadius: const .all(.circular(8)), ), child: Row( children: [ NetworkImgLayer( src: cover!, height: coverSize, - width: coverType == _CoverType.def16_9 + width: coverType == .def16_9 ? coverSize * StyleString.aspectRatio16x9 : coverSize, quality: 100, - borderRadius: const BorderRadius.all( - Radius.circular(6), - ), + borderRadius: const .all(.circular(6)), ), const SizedBox(width: 10), Expanded( child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, + crossAxisAlignment: .start, children: [ Text( '$title\n', maxLines: 2, - overflow: TextOverflow.ellipsis, + overflow: .ellipsis, ), if (pubdate != null) ...[ const Spacer(), @@ -466,8 +456,7 @@ class _SavePanelState extends State { Text( '@$uname', maxLines: 1, - overflow: - TextOverflow.ellipsis, + overflow: .ellipsis, style: TextStyle( color: theme .colorScheme @@ -485,9 +474,7 @@ class _SavePanelState extends State { ), Text( DateFormatUtils.longFormatDs - .format( - DateTime.now(), - ), + .format(.now()), textAlign: TextAlign.end, style: TextStyle( fontSize: 13, @@ -504,12 +491,8 @@ class _SavePanelState extends State { child: Container( width: 88, height: 88, - margin: const EdgeInsets.all( - 12, - ), - padding: const EdgeInsets.all( - 3, - ), + margin: const .all(12), + padding: const .all(3), color: theme.brightness.isDark ? Colors.white : theme.colorScheme.surface, diff --git a/lib/pages/video/widgets/header_mixin.dart b/lib/pages/video/widgets/header_mixin.dart index deb94e50c..84a48f608 100644 --- a/lib/pages/video/widgets/header_mixin.dart +++ b/lib/pages/video/widgets/header_mixin.dart @@ -202,9 +202,9 @@ mixin HeaderMixin on State { data: sliderTheme, child: Slider( min: 0, - max: 10, + max: 11, value: DanmakuOptions.danmakuWeight.toDouble(), - divisions: 10, + divisions: 11, label: DanmakuOptions.danmakuWeight.toString(), onChanged: updateDanmakuWeight, ), diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index bb4b0b331..78578d6ce 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -7,7 +7,6 @@ import 'dart:ui' as ui; import 'package:PiliPlus/common/constants.dart'; import 'package:PiliPlus/http/browser_ua.dart'; import 'package:PiliPlus/http/constants.dart'; -import 'package:PiliPlus/http/init.dart'; import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/http/video.dart'; import 'package:PiliPlus/models/common/account_type.dart'; @@ -47,7 +46,6 @@ import 'package:PiliPlus/utils/storage_pref.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:archive/archive.dart' show getCrc32; import 'package:canvas_danmaku/canvas_danmaku.dart'; -import 'package:dio/dio.dart' show Options; import 'package:easy_debounce/easy_throttle.dart'; import 'package:floating/floating.dart'; import 'package:flutter/foundation.dart' show kDebugMode; @@ -1659,34 +1657,7 @@ class PlPlayerController with BlockConfigMixin { } Future getVideoShot() async { - try { - final res = await Request().get( - '/x/player/videoshot', - queryParameters: { - // 'aid': IdUtils.bv2av(_bvid), - 'bvid': _bvid, - 'cid': cid, - 'index': 1, - }, - options: Options( - headers: { - 'user-agent': BrowserUa.pc, - 'referer': 'https://www.bilibili.com/video/$bvid', - }, - ), - ); - if (res.data['code'] == 0) { - final data = VideoShotData.fromJson(res.data['data']); - if (data.index.isNotEmpty) { - videoShot = Success(data); - return; - } - } - videoShot = const Error(null); - } catch (e) { - videoShot = const Error(null); - if (kDebugMode) debugPrint('getVideoShot: $e'); - } + videoShot = await VideoHttp.videoshot(bvid: bvid, cid: cid!); } void takeScreenshot() {