基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
part of 'collect_library_view.dart';
class _CollectCategories extends StatelessWidget {
const _CollectCategories({
super.key,
required this.controller,
required this.selected,
required this.count,
});
final TabController controller;
final ValueListenable<CollectType?> selected;
final int Function(CollectType?) count;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colors = theme.colorScheme;
// Each lerped weight is a new font instance, so TabBar animates only the
// color and the selected label turns bold once per category change.
final labelStyle =
theme.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w500);
return TabBar(
key: const PageStorageKey('collect-filter-strip'),
controller: controller,
isScrollable: true,
tabAlignment: TabAlignment.start,
dividerHeight: 0,
indicatorSize: TabBarIndicatorSize.tab,
indicatorPadding: const EdgeInsets.symmetric(horizontal: 2),
indicator: BoxDecoration(
color: colors.primaryContainer,
borderRadius: BorderRadius.circular(24),
),
indicatorAnimation: TabIndicatorAnimation.elastic,
labelColor: colors.onPrimaryContainer,
unselectedLabelColor: colors.onSurfaceVariant,
labelStyle: labelStyle,
unselectedLabelStyle: labelStyle,
labelPadding: const EdgeInsets.symmetric(horizontal: 2),
splashFactory: NoSplash.splashFactory,
overlayColor: const WidgetStatePropertyAll(Colors.transparent),
tabs: [
for (final type in _collectCategories)
Tab(
height: 48,
child: Semantics(
label: '${type?.label ?? '全部'},${count(type)} 部',
excludeSemantics: true,
child: ConstrainedBox(
constraints: const BoxConstraints(minWidth: 64),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: ValueListenableBuilder(
valueListenable: selected,
builder: (context, value, _) => Text(
type?.label ?? '全部',
textAlign: TextAlign.center,
style: value == type
? const TextStyle(fontWeight: FontWeight.w700)
: null,
),
),
),
),
),
),
],
);
}
}
class _CollectLayoutSwitch extends StatelessWidget {
const _CollectLayoutSwitch({required this.value, required this.onChanged});
final CollectLayout value;
final ValueChanged<CollectLayout> onChanged;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Row(
mainAxisSize: MainAxisSize.min,
spacing: 2,
children: [
for (final layout in [CollectLayout.cards, CollectLayout.list])
Semantics(
selected: value == layout,
inMutuallyExclusiveGroup: true,
child: IconButton.filledTonal(
tooltip: '${layout.label}布局',
isSelected: value == layout,
onPressed: () => onChanged(layout),
style: ButtonStyle(
minimumSize: const WidgetStatePropertyAll(Size(48, 48)),
visualDensity: VisualDensity.standard,
backgroundColor: WidgetStateProperty.resolveWith((states) =>
states.contains(WidgetState.selected)
? colors.secondaryContainer
: colors.surfaceContainerLow),
foregroundColor: WidgetStateProperty.resolveWith((states) =>
states.contains(WidgetState.selected)
? colors.onSecondaryContainer
: colors.onSurfaceVariant),
shape: WidgetStateProperty.resolveWith((states) =>
RoundedRectangleBorder(
borderRadius: states.contains(WidgetState.pressed)
? BorderRadius.circular(12)
: states.contains(WidgetState.selected)
? BorderRadius.circular(24)
: BorderRadiusDirectional.horizontal(
start: Radius.circular(
layout == CollectLayout.cards ? 24 : 8),
end: Radius.circular(
layout == CollectLayout.list ? 24 : 8),
),
)),
animationDuration: MediaQuery.disableAnimationsOf(context)
? Duration.zero
: const Duration(milliseconds: 200),
),
icon: Icon(layout == CollectLayout.list
? Icons.view_list_rounded
: Icons.grid_view_rounded),
),
),
],
);
}
}
class _CollectSortMenu extends StatelessWidget {
const _CollectSortMenu({
required this.value,
required this.showLabel,
required this.onChanged,
});
final CollectSort value;
final bool showLabel;
final ValueChanged<CollectSort> onChanged;
@override
Widget build(BuildContext context) {
return KazumiMenuButton(
menuChildren: [
for (final sort in CollectSort.values)
KazumiMenuItem(
selected: value == sort,
onPressed: () => onChanged(sort),
label: sort.label,
),
],
builder: (context, toggle) {
return Tooltip(
message: '排序:${value.label}',
child: showLabel
? TextButton.icon(
onPressed: toggle,
style: TextButton.styleFrom(
foregroundColor:
Theme.of(context).colorScheme.onSurfaceVariant,
minimumSize: const Size(48, 48),
),
icon: const Icon(Icons.sort_rounded, size: 20),
label: Text(value.label),
)
: IconButton(
onPressed: toggle,
icon: const Icon(Icons.sort_rounded),
),
);
},
);
}
}