opt: stat widget (#520)

This commit is contained in:
My-Responsitories
2025-03-24 21:09:11 +08:00
committed by GitHub
parent d9a74c43dc
commit 10a22b5186
15 changed files with 149 additions and 142 deletions

View File

@@ -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!)}条弹幕',
)
],
);
}

View 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)}条弹幕';
}

View File

@@ -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" ? "浏览" : "播放"}',
),
],
);
}