From da9bbc0e766236772963a9a4f5f996a9f5851c6c Mon Sep 17 00:00:00 2001 From: guozhigq Date: Tue, 15 Aug 2023 11:09:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80Badge=E7=BB=84=E4=BB=B6=20#9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/widgets/badge.dart | 145 ++++++++++++++---- lib/common/widgets/stat/up.dart | 29 ---- lib/common/widgets/video_card_h.dart | 11 +- lib/common/widgets/video_card_v.dart | 40 ++--- lib/pages/bangumi/introduction/view.dart | 15 +- lib/pages/bangumi/widgets/bangumu_card_v.dart | 17 +- .../dynamics/widgets/live_rcmd_panel.dart | 19 ++- lib/pages/dynamics/widgets/pic_panel.dart | 9 +- lib/pages/dynamics/widgets/video_panel.dart | 8 +- lib/pages/history/widgets/item.dart | 27 ++-- lib/pages/live/widgets/live_item.dart | 9 +- .../widgets/media_bangumi_panel.dart | 9 +- .../detail/reply/widgets/reply_item.dart | 56 +++---- 13 files changed, 242 insertions(+), 152 deletions(-) delete mode 100644 lib/common/widgets/stat/up.dart diff --git a/lib/common/widgets/badge.dart b/lib/common/widgets/badge.dart index 035be598..baa2bff2 100644 --- a/lib/common/widgets/badge.dart +++ b/lib/common/widgets/badge.dart @@ -1,33 +1,120 @@ import 'package:flutter/material.dart'; -Widget pBadge( - text, - context, - double? top, - double? right, - double? bottom, - double? left, { - type = 'primary', -}) { - Color bgColor = Theme.of(context).colorScheme.primary; - Color color = Theme.of(context).colorScheme.onPrimary; - if (type == 'gray') { - bgColor = Colors.black54.withOpacity(0.4); - color = Colors.white; - } - return Positioned( - top: top, - left: left, - right: right, - bottom: bottom, - child: Container( - padding: const EdgeInsets.symmetric(vertical: 1, horizontal: 6), - decoration: - BoxDecoration(borderRadius: BorderRadius.circular(4), color: bgColor), - child: Text( - text, - style: TextStyle(fontSize: 11, color: color), +// Widget pBadge( +// text, +// context, +// double? top, +// double? right, +// double? bottom, +// double? left, { +// type = 'primary', +// }) { +// Color bgColor = Theme.of(context).colorScheme.primary; +// Color color = Theme.of(context).colorScheme.onPrimary; +// if (type == 'gray') { +// bgColor = Colors.black54.withOpacity(0.4); +// color = Colors.white; +// } +// return Positioned( +// top: top, +// left: left, +// right: right, +// bottom: bottom, +// child: Container( +// padding: const EdgeInsets.symmetric(vertical: 1, horizontal: 6), +// decoration: +// BoxDecoration(borderRadius: BorderRadius.circular(4), color: bgColor), +// child: Text( +// text, +// style: TextStyle(fontSize: 11, color: color), +// ), +// ), +// ); +// } + +class PBadge extends StatelessWidget { + final String? text; + final double? top; + final double? right; + final double? bottom; + final double? left; + final String? type; + final String? size; + final String? stack; + final double? fs; + + const PBadge({ + super.key, + this.text, + this.top, + this.right, + this.bottom, + this.left, + this.type = 'primary', + this.size = 'medium', + this.stack = 'position', + this.fs = 11, + }); + + @override + Widget build(BuildContext context) { + ColorScheme t = Theme.of(context).colorScheme; + // 背景色 + Color bgColor = t.primary; + // 前景色 + Color color = t.onPrimary; + // 边框色 + Color borderColor = Colors.transparent; + if (type == 'gray') { + bgColor = Colors.black54.withOpacity(0.4); + color = Colors.white; + } + if (type == 'color') { + bgColor = t.primaryContainer.withOpacity(0.6); + color = t.primary; + } + if (type == 'line') { + bgColor = Colors.transparent; + color = t.primary; + borderColor = t.primary; + } + + EdgeInsets paddingStyle = + const EdgeInsets.symmetric(vertical: 1, horizontal: 6); + double fontSize = 11; + BorderRadius br = BorderRadius.circular(4); + + if (size == 'small') { + paddingStyle = const EdgeInsets.symmetric(vertical: 0, horizontal: 3); + fontSize = 11; + br = BorderRadius.circular(3); + } + + Widget content = Container( + padding: paddingStyle, + decoration: BoxDecoration( + borderRadius: br, + color: bgColor, + border: Border.all(color: borderColor), ), - ), - ); + child: Text( + text!, + style: TextStyle(fontSize: fs ?? fontSize, color: color), + ), + ); + if (stack == 'position') { + return Positioned( + top: top, + left: left, + right: right, + bottom: bottom, + child: content, + ); + } else { + return Padding( + padding: const EdgeInsets.only(right: 5), + child: content, + ); + } + } } diff --git a/lib/common/widgets/stat/up.dart b/lib/common/widgets/stat/up.dart deleted file mode 100644 index fa5539eb..00000000 --- a/lib/common/widgets/stat/up.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:flutter/material.dart'; - -class UpTag extends StatelessWidget { - final String? tagText; - const UpTag({super.key, this.tagText = 'UP'}); - @override - Widget build(BuildContext context) { - Color primary = Theme.of(context).colorScheme.primary; - return Container( - padding: const EdgeInsets.fromLTRB(3, 1, 3, 1), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(3), - color: tagText == 'UP' ? primary : null, - border: Border.all(color: primary)), - margin: const EdgeInsets.only(right: 5), - child: Center( - child: Text( - tagText!, - style: TextStyle( - fontSize: 9, - color: tagText == 'UP' - ? Theme.of(context).colorScheme.onPrimary - : primary, - ), - ), - ), - ); - } -} diff --git a/lib/common/widgets/video_card_h.dart b/lib/common/widgets/video_card_h.dart index 1a61f922..7053cc93 100644 --- a/lib/common/widgets/video_card_h.dart +++ b/lib/common/widgets/video_card_h.dart @@ -82,9 +82,14 @@ class VideoCardH extends StatelessWidget { height: maxHeight, ), ), - pBadge(Utils.timeFormat(videoItem.duration!), - context, null, 6.0, 6.0, null, - type: 'gray'), + PBadge( + text: Utils.timeFormat(videoItem.duration!), + top: null, + right: 6.0, + bottom: 6.0, + left: null, + type: 'gray', + ), // if (videoItem.rcmdReason != null && // videoItem.rcmdReason.content != '') // pBadge(videoItem.rcmdReason.content, context, diff --git a/lib/common/widgets/video_card_v.dart b/lib/common/widgets/video_card_v.dart index ffc6b8bf..c15f4100 100644 --- a/lib/common/widgets/video_card_v.dart +++ b/lib/common/widgets/video_card_v.dart @@ -2,8 +2,8 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:pilipala/common/constants.dart'; +import 'package:pilipala/common/widgets/badge.dart'; import 'package:pilipala/common/widgets/stat/danmu.dart'; -import 'package:pilipala/common/widgets/stat/up.dart'; import 'package:pilipala/common/widgets/stat/view.dart'; import 'package:pilipala/http/search.dart'; import 'package:pilipala/http/user.dart'; @@ -164,35 +164,23 @@ class VideoContent extends StatelessWidget { Row( children: [ if (videoItem.goto == 'bangumi') ...[ - UpTag( - tagText: videoItem.bangumiBadge, - ), + PBadge( + text: videoItem.bangumiBadge, + stack: 'normal', + size: 'small', + type: 'line', + fs: 9, + ) ], if (videoItem.rcmdReason != null && videoItem.rcmdReason.content != '') ...[ - Container( - padding: const EdgeInsets.fromLTRB(3, 1, 3, 1), - decoration: BoxDecoration( - color: Theme.of(context) - .colorScheme - .primaryContainer - .withOpacity(0.6), - borderRadius: BorderRadius.circular(3)), - child: Center( - child: Text( - videoItem.rcmdReason.content, - style: TextStyle( - fontSize: 11, - color: Theme.of(context).colorScheme.primary, - ), - ), - )), - const SizedBox(width: 4) + PBadge( + text: videoItem.rcmdReason.content, + stack: 'normal', + size: 'small', + type: 'color', + ) ], - if (videoItem.adInfo != null) - const UpTag( - tagText: '推广', - ), Expanded( child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) { diff --git a/lib/pages/bangumi/introduction/view.dart b/lib/pages/bangumi/introduction/view.dart index 4af7955d..86724cab 100644 --- a/lib/pages/bangumi/introduction/view.dart +++ b/lib/pages/bangumi/introduction/view.dart @@ -161,13 +161,14 @@ class _BangumiInfoState extends State { ), if (bangumiItem != null && bangumiItem!.rating != null) - pBadge( - '评分 ${!widget.loadingStatus ? widget.bangumiDetail!.rating!['score']! : bangumiItem!.rating!['score']!}', - context, - null, - 6, - 6, - null), + PBadge( + text: + '评分 ${!widget.loadingStatus ? widget.bangumiDetail!.rating!['score']! : bangumiItem!.rating!['score']!}', + top: null, + right: 6, + bottom: 6, + left: null, + ), ], ), const SizedBox(width: 10), diff --git a/lib/pages/bangumi/widgets/bangumu_card_v.dart b/lib/pages/bangumi/widgets/bangumu_card_v.dart index fdc67c1a..47629331 100644 --- a/lib/pages/bangumi/widgets/bangumu_card_v.dart +++ b/lib/pages/bangumi/widgets/bangumu_card_v.dart @@ -97,10 +97,21 @@ class BangumiCardV extends StatelessWidget { ), ), if (bangumiItem.badge != null) - pBadge(bangumiItem.badge, context, 6, 6, null, null), + PBadge( + text: bangumiItem.badge, + top: 6, + right: 6, + bottom: null, + left: null), if (bangumiItem.order != null) - pBadge(bangumiItem.order, context, null, null, 6, 6, - type: 'gray'), + PBadge( + text: bangumiItem.order, + top: null, + right: null, + bottom: 6, + left: 6, + type: 'gray', + ), ], ); }), diff --git a/lib/pages/dynamics/widgets/live_rcmd_panel.dart b/lib/pages/dynamics/widgets/live_rcmd_panel.dart index 2b4dedac..9589f919 100644 --- a/lib/pages/dynamics/widgets/live_rcmd_panel.dart +++ b/lib/pages/dynamics/widgets/live_rcmd_panel.dart @@ -77,10 +77,21 @@ Widget liveRcmdPanel(item, context, {floor = 1}) { src: item.modules.moduleDynamic.major.liveRcmd.cover, ), ), - pBadge(watchedShow['text_large'], context, 6, 56, null, null, - type: 'gray'), - pBadge( - liveStatus == 1 ? '直播中' : '直播结束', context, 6, 6, null, null), + PBadge( + text: watchedShow['text_large'], + top: 6, + right: 56, + bottom: null, + left: null, + type: 'gray', + ), + PBadge( + text: liveStatus == 1 ? '直播中' : '直播结束', + top: 6, + right: 6, + bottom: null, + left: null, + ), Positioned( left: 0, right: 0, diff --git a/lib/pages/dynamics/widgets/pic_panel.dart b/lib/pages/dynamics/widgets/pic_panel.dart index ef4691cb..a56ac8f7 100644 --- a/lib/pages/dynamics/widgets/pic_panel.dart +++ b/lib/pages/dynamics/widgets/pic_panel.dart @@ -85,7 +85,14 @@ Widget picWidget(item, context) { children: list, ), if (len == 1 && origAspectRatio < 0.4) - pBadge('长图', context, null, null, 6.0, 6.0, type: 'gray') + const PBadge( + text: '长图', + top: null, + right: null, + bottom: 6.0, + left: 6.0, + type: 'gray', + ) ], ), ); diff --git a/lib/pages/dynamics/widgets/video_panel.dart b/lib/pages/dynamics/widgets/video_panel.dart index 0b65a071..04c1ae19 100644 --- a/lib/pages/dynamics/widgets/video_panel.dart +++ b/lib/pages/dynamics/widgets/video_panel.dart @@ -89,7 +89,13 @@ Widget videoSeasonWidget(item, context, type, {floor = 1}) { ), ), if (content.badge != null && type == 'pgc') - pBadge(content.badge['text'], context, 8.0, 10.0, null, null), + PBadge( + text: content.badge['text'], + top: 8.0, + right: 10.0, + bottom: null, + left: null, + ), Positioned( left: 0, right: 0, diff --git a/lib/pages/history/widgets/item.dart b/lib/pages/history/widgets/item.dart index 2bf06c3b..bf34ac34 100644 --- a/lib/pages/history/widgets/item.dart +++ b/lib/pages/history/widgets/item.dart @@ -147,23 +147,26 @@ class HistoryItem extends StatelessWidget { if (!BusinessType .hiddenDurationType.hiddenDurationType .contains(videoItem.history.business)) - pBadge( - videoItem.progress == -1 - ? '已看完' - : '${Utils.timeFormat(videoItem.progress!)}/${Utils.timeFormat(videoItem.duration!)}', - context, - null, - 6.0, - 6.0, - null, - type: 'gray'), + PBadge( + text: videoItem.progress == -1 + ? '已看完' + : '${Utils.timeFormat(videoItem.progress!)}/${Utils.timeFormat(videoItem.duration!)}', + right: 6.0, + bottom: 6.0, + type: 'gray', + ), // 右上角 if (BusinessType.showBadge.showBadge .contains(videoItem.history.business) || videoItem.history.business == BusinessType.live.type) - pBadge(videoItem.badge, context, 6.0, 6.0, - null, null), + PBadge( + text: videoItem.badge, + top: 6.0, + right: 6.0, + bottom: null, + left: null, + ), ], ); }, diff --git a/lib/pages/live/widgets/live_item.dart b/lib/pages/live/widgets/live_item.dart index 9a04255a..3e6df115 100644 --- a/lib/pages/live/widgets/live_item.dart +++ b/lib/pages/live/widgets/live_item.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:pilipala/common/constants.dart'; +import 'package:pilipala/common/widgets/badge.dart'; import 'package:pilipala/models/live/item.dart'; -import 'package:pilipala/pages/video/detail/reply/widgets/reply_item.dart'; import 'package:pilipala/utils/utils.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart'; @@ -121,7 +121,12 @@ class LiveContent extends StatelessWidget { ), Row( children: [ - const UpTag(), + const PBadge( + text: 'UP', + size: 'small', + stack: 'normal', + fs: 9, + ), Expanded( child: Text( liveItem.uname, diff --git a/lib/pages/searchPanel/widgets/media_bangumi_panel.dart b/lib/pages/searchPanel/widgets/media_bangumi_panel.dart index 9dab4699..b17c74de 100644 --- a/lib/pages/searchPanel/widgets/media_bangumi_panel.dart +++ b/lib/pages/searchPanel/widgets/media_bangumi_panel.dart @@ -41,8 +41,13 @@ Widget searchMbangumiPanel(BuildContext context, ctr, list) { height: 148, src: i.cover, ), - pBadge(i.mediaType == 1 ? '番剧' : '国创', context, 6.0, 4.0, - null, null) + PBadge( + text: i.mediaType == 1 ? '番剧' : '国创', + top: 6.0, + right: 4.0, + bottom: null, + left: null, + ) ], ), const SizedBox(width: 10), diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index ba71b9da..7aab2a13 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -2,6 +2,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; +import 'package:pilipala/common/widgets/badge.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart'; import 'package:pilipala/models/common/reply_type.dart'; import 'package:pilipala/models/video/reply/item.dart'; @@ -139,7 +140,13 @@ class ReplyItem extends StatelessWidget { height: 11, ), const SizedBox(width: 6), - if (replyItem!.isUp!) const UpTag(), + if (replyItem!.isUp!) + const PBadge( + text: 'UP', + size: 'small', + stack: 'normal', + fs: 9, + ), ], ), Positioned( @@ -208,8 +215,15 @@ class ReplyItem extends StatelessWidget { children: [ if (replyItem!.isTop!) const WidgetSpan( - alignment: PlaceholderAlignment.top, - child: UpTag(tagText: 'TOP')), + alignment: PlaceholderAlignment.top, + child: PBadge( + text: 'TOP', + size: 'small', + stack: 'normal', + type: 'line', + fs: 9, + ), + ), buildContent(context, replyItem!, replyReply, null), ], ), @@ -392,7 +406,12 @@ class ReplyItemRow extends StatelessWidget { if (replies![i].isUp) const WidgetSpan( alignment: PlaceholderAlignment.top, - child: UpTag(), + child: PBadge( + text: 'UP', + size: 'small', + stack: 'normal', + fs: 9, + ), ), buildContent( context, replies![i], replyReply, replyItem), @@ -759,32 +778,3 @@ InlineSpan buildContent( // spanChilds.add(TextSpan(text: matchMember)); return TextSpan(children: spanChilds); } - -class UpTag extends StatelessWidget { - final String? tagText; - const UpTag({super.key, this.tagText = 'UP'}); - @override - Widget build(BuildContext context) { - Color primary = Theme.of(context).colorScheme.primary; - return Container( - width: 24, - height: 14, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(3), - color: tagText == 'UP' ? primary : null, - border: Border.all(color: primary)), - margin: const EdgeInsets.only(right: 4), - child: Center( - child: Text( - tagText!, - style: TextStyle( - fontSize: 9, - color: tagText == 'UP' - ? Theme.of(context).colorScheme.onPrimary - : primary, - ), - ), - ), - ); - } -}