mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: stat widget (#520)
This commit is contained in:
committed by
GitHub
parent
d9a74c43dc
commit
10a22b5186
@@ -1,36 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
|
||||
Widget statDanMu({
|
||||
required BuildContext context,
|
||||
String? theme,
|
||||
dynamic danmu,
|
||||
String? size,
|
||||
Color? textColor,
|
||||
}) {
|
||||
Map<String, Color> colorObject = {
|
||||
'white': Colors.white,
|
||||
'gray': Theme.of(context).colorScheme.outline.withOpacity(0.8),
|
||||
'black': Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
|
||||
};
|
||||
Color color = textColor ?? colorObject[theme]!;
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.subtitles_outlined,
|
||||
size: 14,
|
||||
color: color,
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
Utils.numFormat(danmu!),
|
||||
style: TextStyle(
|
||||
fontSize: size == 'medium' ? 12 : 11,
|
||||
color: color,
|
||||
),
|
||||
overflow: TextOverflow.clip,
|
||||
semanticsLabel: '${Utils.numFormat(danmu!)}条弹幕',
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
93
lib/common/widgets/stat/stat.dart
Normal file
93
lib/common/widgets/stat/stat.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract class _StatItemBase extends StatelessWidget {
|
||||
final BuildContext context;
|
||||
final Object value;
|
||||
final String? theme;
|
||||
final String? size;
|
||||
final Color? textColor;
|
||||
final double iconSize;
|
||||
|
||||
const _StatItemBase({
|
||||
required this.context,
|
||||
required this.value,
|
||||
this.theme,
|
||||
this.size,
|
||||
this.textColor,
|
||||
this.iconSize = 13,
|
||||
});
|
||||
|
||||
IconData get iconData;
|
||||
String get semanticsLabel;
|
||||
|
||||
Color get color {
|
||||
return textColor ??
|
||||
switch (theme) {
|
||||
'gray' => Theme.of(context).colorScheme.outline.withOpacity(0.8),
|
||||
'black' => Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
|
||||
_ => Colors.white,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
iconData,
|
||||
size: iconSize,
|
||||
color: color,
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
Utils.numFormat(value),
|
||||
style: TextStyle(
|
||||
fontSize: size == 'medium' ? 12 : 11,
|
||||
color: color,
|
||||
),
|
||||
overflow: TextOverflow.clip,
|
||||
semanticsLabel: semanticsLabel,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StatView extends _StatItemBase {
|
||||
final String? goto;
|
||||
|
||||
const StatView({
|
||||
required super.context,
|
||||
required super.value,
|
||||
this.goto,
|
||||
super.theme,
|
||||
super.size,
|
||||
super.textColor,
|
||||
}) : super(iconSize: 13);
|
||||
|
||||
@override
|
||||
IconData get iconData => goto == 'picture'
|
||||
? Icons.remove_red_eye_outlined
|
||||
: Icons.play_circle_outlined;
|
||||
|
||||
@override
|
||||
String get semanticsLabel =>
|
||||
'${Utils.numFormat(value)}次${goto == "picture" ? "浏览" : "播放"}';
|
||||
}
|
||||
|
||||
class StatDanMu extends _StatItemBase {
|
||||
const StatDanMu({
|
||||
required super.context,
|
||||
required super.value,
|
||||
super.theme,
|
||||
super.size,
|
||||
super.textColor,
|
||||
}) : super(iconSize: 14);
|
||||
|
||||
@override
|
||||
IconData get iconData => Icons.subtitles_outlined;
|
||||
|
||||
@override
|
||||
String get semanticsLabel => '${Utils.numFormat(value)}条弹幕';
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
|
||||
Widget statView({
|
||||
required BuildContext context,
|
||||
String? theme,
|
||||
dynamic view,
|
||||
String? size,
|
||||
String? goto,
|
||||
Color? textColor,
|
||||
}) {
|
||||
Map<String, Color> colorObject = {
|
||||
'white': Colors.white,
|
||||
'gray': Theme.of(context).colorScheme.outline.withOpacity(0.8),
|
||||
'black': Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
|
||||
};
|
||||
Color color = textColor ?? colorObject[theme]!;
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
goto == 'picture'
|
||||
? Icons.remove_red_eye_outlined
|
||||
: Icons.play_circle_outlined,
|
||||
size: 13,
|
||||
color: color,
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
Utils.numFormat(view!),
|
||||
style: TextStyle(
|
||||
fontSize: size == 'medium' ? 12 : 11,
|
||||
color: color,
|
||||
),
|
||||
overflow: TextOverflow.clip,
|
||||
semanticsLabel:
|
||||
'${Utils.numFormat(view!)}次${goto == "picture" ? "浏览" : "播放"}',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -7,8 +7,7 @@ import '../../utils/utils.dart';
|
||||
import '../constants.dart';
|
||||
import 'badge.dart';
|
||||
import 'network_img_layer.dart';
|
||||
import 'stat/danmu.dart';
|
||||
import 'stat/view.dart';
|
||||
import 'stat/stat.dart';
|
||||
import 'video_popup_menu.dart';
|
||||
|
||||
// 视频卡片 - 水平布局
|
||||
@@ -265,18 +264,18 @@ class VideoCardH extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
if (showView) ...[
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: videoItem.stat.view as int,
|
||||
value: videoItem.stat.view!,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
if (showDanmaku)
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu: videoItem.stat.danmu as int,
|
||||
value: videoItem.stat.danmu!,
|
||||
),
|
||||
const Spacer(),
|
||||
if (source == 'normal') const SizedBox(width: 24),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:PiliPlus/common/widgets/image_save.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/danmu.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/common/widgets/video_popup_menu.dart';
|
||||
import 'package:PiliPlus/common/widgets/video_progress_indicator.dart';
|
||||
import 'package:PiliPlus/models/space_archive/item.dart';
|
||||
@@ -180,19 +179,19 @@ class VideoCardHMemberVideo extends StatelessWidget {
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
// view: videoItem.season?['view_content'] ??
|
||||
// videoItem.viewContent,
|
||||
view: videoItem.viewContent,
|
||||
value: videoItem.viewContent!,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
// danmu: videoItem.season?['danmaku'] ?? videoItem.danmaku,
|
||||
danmu: videoItem.danmaku,
|
||||
value: videoItem.danmaku!,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -5,8 +5,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../models/home/rcmd/result.dart';
|
||||
import '../../models/model_rec_video_item.dart';
|
||||
import 'stat/danmu.dart';
|
||||
import 'stat/view.dart';
|
||||
import 'stat/stat.dart';
|
||||
import '../../http/dynamics.dart';
|
||||
import '../../utils/id_utils.dart';
|
||||
import '../../utils/utils.dart';
|
||||
@@ -260,18 +259,18 @@ class VideoCardV extends StatelessWidget {
|
||||
Widget videoStat(context) {
|
||||
return Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: videoItem.stat.view,
|
||||
value: videoItem.stat.view!,
|
||||
goto: videoItem.goto,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
if (videoItem.goto != 'picture')
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu: videoItem.stat.danmu,
|
||||
value: videoItem.stat.danmu!,
|
||||
),
|
||||
if (videoItem is RecVideoItemModel) ...<Widget>[
|
||||
const Spacer(),
|
||||
|
||||
@@ -12,8 +12,7 @@ import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/danmu.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/models/bangumi/info.dart';
|
||||
import 'package:PiliPlus/pages/bangumi/widgets/bangumi_panel.dart';
|
||||
import 'package:PiliPlus/pages/video/detail/index.dart';
|
||||
@@ -322,19 +321,19 @@ class _BangumiInfoState extends State<BangumiInfo>
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: !widget.isLoading
|
||||
value: !widget.isLoading
|
||||
? widget.bangumiDetail!.stat!['views']
|
||||
: bangumiItem!.stat!['views'],
|
||||
size: 'medium',
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu: !widget.isLoading
|
||||
value: !widget.isLoading
|
||||
? widget
|
||||
.bangumiDetail!.stat!['danmakus']
|
||||
: bangumiItem!.stat!['danmakus'],
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'package:PiliPlus/pages/common/common_collapse_slide_page.dart';
|
||||
import 'package:PiliPlus/pages/search/widgets/search_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/danmu.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../../utils/utils.dart';
|
||||
@@ -79,17 +78,17 @@ class _IntroDetailState extends CommonCollapseSlidePageState<IntroDetail> {
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: widget.bangumiDetail!.stat!['views'],
|
||||
value: widget.bangumiDetail!.stat!['views'],
|
||||
size: 'medium',
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu: widget.bangumiDetail!.stat!['danmakus'],
|
||||
value: widget.bangumiDetail!.stat!['danmakus'],
|
||||
size: 'medium',
|
||||
),
|
||||
],
|
||||
|
||||
@@ -6,8 +6,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/danmu.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/http/search.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
@@ -192,16 +191,16 @@ class FavVideoCardH extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: videoItem.cntInfo['play'],
|
||||
value: videoItem.cntInfo['play'],
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu: videoItem.cntInfo['danmaku'],
|
||||
value: videoItem.cntInfo['danmaku'],
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/http/search.dart';
|
||||
import 'package:PiliPlus/models/member/coin.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
@@ -78,9 +78,9 @@ class MemberCoinsItem extends StatelessWidget {
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
view: coinItem.view,
|
||||
value: coinItem.view!,
|
||||
theme: 'gray',
|
||||
),
|
||||
const Spacer(),
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/http/search.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
|
||||
@@ -72,9 +72,9 @@ class MemberSeasonsItem extends StatelessWidget {
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
view: seasonItem.view,
|
||||
value: seasonItem.view,
|
||||
theme: 'gray',
|
||||
),
|
||||
const Spacer(),
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'package:PiliPlus/common/widgets/image_save.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/danmu.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/http/search.dart';
|
||||
import 'package:PiliPlus/models/common/search_type.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
@@ -127,16 +126,16 @@ class SubVideoCardH extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: videoItem.cntInfo?['play'],
|
||||
value: videoItem.cntInfo?['play'],
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu: videoItem.cntInfo?['danmaku'],
|
||||
value: videoItem.cntInfo?['danmaku'],
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
|
||||
@@ -17,8 +17,7 @@ import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
import 'package:PiliPlus/pages/video/detail/index.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/danmu.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/models/video_detail_res.dart';
|
||||
import 'package:PiliPlus/pages/video/detail/introduction/controller.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
@@ -614,20 +613,20 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
children: [
|
||||
Row(
|
||||
children: <Widget>[
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: !widget.loadingStatus
|
||||
value: !widget.loadingStatus
|
||||
? videoDetail.stat?.view ?? '-'
|
||||
: videoItem['stat']?.view ?? '-',
|
||||
size: 'medium',
|
||||
textColor: t.colorScheme.outline,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu: !widget.loadingStatus
|
||||
value: !widget.loadingStatus
|
||||
? videoDetail.stat?.danmu ?? '-'
|
||||
: videoItem['stat']?.danmu ?? '-',
|
||||
size: 'medium',
|
||||
|
||||
@@ -4,8 +4,7 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/danmu.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
|
||||
@Deprecated('deprecated')
|
||||
@@ -55,17 +54,17 @@ class IntroDetail extends StatelessWidget {
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: videoDetail!.stat!.view,
|
||||
value: videoDetail!.stat!.view,
|
||||
size: 'medium',
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu: videoDetail!.stat!.danmu,
|
||||
value: videoDetail!.stat!.danmu,
|
||||
size: 'medium',
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'package:PiliPlus/common/widgets/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/danmu.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/view.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/pages/common/common_collapse_slide_page.dart';
|
||||
import 'package:PiliPlus/pages/common/common_slide_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -232,16 +231,16 @@ class _MediaListPanelState extends CommonSlidePageState<MediaListPanel> {
|
||||
const SizedBox(height: 2),
|
||||
Row(
|
||||
children: [
|
||||
statView(
|
||||
StatView(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
view: item.cntInfo!['play'] as int,
|
||||
value: item.cntInfo!['play'] as int,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
statDanMu(
|
||||
StatDanMu(
|
||||
context: context,
|
||||
theme: 'gray',
|
||||
danmu:
|
||||
value:
|
||||
item.cntInfo!['danmaku'] as int,
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user