Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

feat(player): materialize gesture HUDs

Predidit2bd757f6818e
diff --git a/lib/pages/player/controller/player_panel_controller.dart b/lib/pages/player/controller/player_panel_controller.dart
index 7be2d5a8..77ba4750 100644
--- a/lib/pages/player/controller/player_panel_controller.dart
+++ b/lib/pages/player/controller/player_panel_controller.dart
@@ -36,6 +36,7 @@ abstract class _PlayerPanelController with Store {
bool brightnessSeeking = false;
@observable
bool volumeSeeking = false;
+ int seekDirection = 0;
@observable
bool canHidePlayerPanel = true;
@@ -49,6 +50,7 @@ abstract class _PlayerPanelController with Store {
showPlaySpeed = false;
brightnessSeeking = false;
volumeSeeking = false;
+ seekDirection = 0;
canHidePlayerPanel = true;
}
}
diff --git a/lib/pages/player/player_adjustment_hud.dart b/lib/pages/player/player_adjustment_hud.dart
index aa5ca20e..b8fb89ca 100644
--- a/lib/pages/player/player_adjustment_hud.dart
+++ b/lib/pages/player/player_adjustment_hud.dart
@@ -1,6 +1,7 @@
import 'dart:ui';
import 'package:flutter/material.dart';
+import 'package:kazumi/utils/format.dart';
enum PlayerAdjustmentHudType {
brightness,
@@ -158,7 +159,8 @@ class _PlayerAdjustmentHudState extends State<PlayerAdjustmentHud> {
duration: duration,
curve: Curves.easeOutCubic,
width: 200,
- padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
+ padding:
+ const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
decoration: BoxDecoration(
color: surface,
borderRadius: BorderRadius.circular(30),
@@ -521,3 +523,431 @@ class _HudSliderThumbShape extends SliderComponentShape {
);
}
}
+
+class PlayerSeekHud extends StatefulWidget {
+ const PlayerSeekHud({
+ super.key,
+ required this.visible,
+ required this.currentPosition,
+ required this.playerPosition,
+ required this.duration,
+ required this.direction,
+ this.disableAnimations = false,
+ });
+
+ final bool visible;
+ final Duration currentPosition;
+ final Duration playerPosition;
+ final Duration duration;
+ final int direction;
+ final bool disableAnimations;
+
+ @override
+ State<PlayerSeekHud> createState() => _PlayerSeekHudState();
+}
+
+class _PlayerSeekHudState extends State<PlayerSeekHud> {
+ late Duration _displayCurrentPosition;
+ late Duration _displayPlayerPosition;
+ late Duration _displayDuration;
+ late int _displayDirection;
+ bool _snapProgressOnNextBuild = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _displayCurrentPosition = widget.currentPosition;
+ _displayPlayerPosition = widget.playerPosition;
+ _displayDuration = widget.duration;
+ _displayDirection = widget.direction;
+ }
+
+ @override
+ void didUpdateWidget(covariant PlayerSeekHud oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (widget.visible) {
+ _displayCurrentPosition = widget.currentPosition;
+ _displayPlayerPosition = widget.playerPosition;
+ _displayDuration = widget.duration;
+ _displayDirection = widget.direction;
+ if (!oldWidget.visible) {
+ _snapProgressOnNextBuild = true;
+ }
+ }
+ }
+
+ int get _effectiveDirection {
+ final positionDirection =
+ _displayCurrentPosition.compareTo(_displayPlayerPosition);
+ if (positionDirection != 0) {
+ return positionDirection;
+ }
+ return _displayDirection;
+ }
+
+ bool get _isForward => _effectiveDirection >= 0;
+
+ String get _offsetText {
+ final offsetMs = (_displayCurrentPosition.inMilliseconds -
+ _displayPlayerPosition.inMilliseconds)
+ .abs();
+ final sign = _isForward ? '+' : '-';
+ return '$sign${durationToString(Duration(milliseconds: offsetMs))}';
+ }
+
+ double get _progress {
+ final durationMs = _displayDuration.inMilliseconds;
+ if (durationMs <= 0) {
+ return 0;
+ }
+ return (_displayCurrentPosition.inMilliseconds / durationMs)
+ .clamp(0.0, 1.0)
+ .toDouble();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+ final accent = colorScheme.secondaryContainer;
+ final container = colorScheme.secondary;
+ final onContainer = colorScheme.onSecondary;
+ final progressFill = colorScheme.secondaryContainer.withValues(alpha: 0.46);
+ final surface = colorScheme.surfaceContainerHighest.withValues(alpha: 0.74);
+ final border = colorScheme.outlineVariant.withValues(alpha: 0.34);
+ final duration = widget.disableAnimations
+ ? Duration.zero
+ : const Duration(milliseconds: 200);
+ final snapProgress = _snapProgressOnNextBuild;
+ final icon =
+ _isForward ? Icons.fast_forward_rounded : Icons.fast_rewind_rounded;
+
+ if (snapProgress) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (!mounted) {
+ return;
+ }
+ setState(() {
+ _snapProgressOnNextBuild = false;
+ });
+ });
+ }
+
+ return IgnorePointer(
+ child: AnimatedOpacity(
+ opacity: widget.visible ? 1 : 0,
+ duration: duration,
+ curve: Curves.easeOutCubic,
+ child: AnimatedSlide(
+ offset: widget.visible ? Offset.zero : const Offset(0, -0.18),
+ duration: duration,
+ curve: Curves.easeOutCubic,
+ child: AnimatedScale(
+ scale: widget.visible ? 1 : 0.92,
+ duration: duration,
+ curve: Curves.easeOutBack,
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(30),
+ child: BackdropFilter(
+ filter: ImageFilter.blur(sigmaX: 18, sigmaY: 18),
+ child: AnimatedContainer(
+ duration: duration,
+ curve: Curves.easeOutCubic,
+ width: 248,
+ decoration: BoxDecoration(
+ color: surface,
+ borderRadius: BorderRadius.circular(30),
+ border: Border.all(color: border),
+ boxShadow: [
+ BoxShadow(
+ color: accent.withValues(
+ alpha: widget.visible ? 0.24 : 0,
+ ),
+ blurRadius: 32,
+ spreadRadius: 1,
+ ),
+ BoxShadow(
+ color: Colors.black.withValues(alpha: 0.28),
+ blurRadius: 24,
+ offset: const Offset(0, 12),
+ ),
+ ],
+ ),
+ child: Stack(
+ children: [
+ Positioned.fill(
+ child: TweenAnimationBuilder<double>(
+ tween: Tween<double>(end: _progress),
+ duration: widget.disableAnimations || snapProgress
+ ? Duration.zero
+ : const Duration(milliseconds: 180),
+ curve: Curves.easeOutCubic,
+ builder: (context, animatedProgress, child) {
+ return _SeekProgressBackground(
+ progress: animatedProgress,
+ color: progressFill,
+ );
+ },
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(
+ vertical: 8,
+ horizontal: 10,
+ ),
+ child: Row(
+ children: [
+ AnimatedContainer(
+ duration: duration,
+ curve: Curves.easeOutCubic,
+ width: 36,
+ height: 36,
+ decoration: BoxDecoration(
+ color: container.withValues(alpha: 0.92),
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: AnimatedSwitcher(
+ duration: duration,
+ switchInCurve: Curves.easeOutBack,
+ switchOutCurve: Curves.easeInCubic,
+ transitionBuilder: (child, animation) {
+ return ScaleTransition(
+ scale: animation,
+ child: FadeTransition(
+ opacity: animation,
+ child: child,
+ ),
+ );
+ },
+ child: Icon(
+ icon,
+ key: ValueKey(icon),
+ color: onContainer,
+ size: 22,
+ ),
+ ),
+ ),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ _offsetText,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: Theme.of(context)
+ .textTheme
+ .labelLarge
+ ?.copyWith(
+ color: colorScheme.onSurface,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ const SizedBox(height: 1),
+ Text(
+ '${durationToString(_displayCurrentPosition)} / ${durationToString(_displayDuration)}',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: Theme.of(context)
+ .textTheme
+ .bodySmall
+ ?.copyWith(
+ color: colorScheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _SeekProgressBackground extends StatelessWidget {
+ const _SeekProgressBackground({
+ required this.progress,
+ required this.color,
+ });
+
+ final double progress;
+ final Color color;
+
+ @override
+ Widget build(BuildContext context) {
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ final width = constraints.maxWidth * progress.clamp(0.0, 1.0);
+ return Align(
+ alignment: Alignment.centerLeft,
+ child: Container(
+ width: width,
+ color: color,
+ ),
+ );
+ },
+ );
+ }
+}
+
+class PlayerSpeedHud extends StatefulWidget {
+ const PlayerSpeedHud({
+ super.key,
+ required this.visible,
+ required this.speed,
+ this.disableAnimations = false,
+ });
+
+ final bool visible;
+ final double speed;
+ final bool disableAnimations;
+
+ @override
+ State<PlayerSpeedHud> createState() => _PlayerSpeedHudState();
+}
+
+class _PlayerSpeedHudState extends State<PlayerSpeedHud> {
+ late double _displaySpeed;
+
+ @override
+ void initState() {
+ super.initState();
+ _displaySpeed = widget.speed;
+ }
+
+ @override
+ void didUpdateWidget(covariant PlayerSpeedHud oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (widget.visible) {
+ _displaySpeed = widget.speed;
+ }
+ }
+
+ String get _speedText => '${_displaySpeed.toStringAsFixed(1)}x';
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+ final accent = colorScheme.inversePrimary;
+ final container = colorScheme.inverseSurface;
+ final onContainer = colorScheme.onInverseSurface;
+ final surface = colorScheme.surfaceContainerHighest.withValues(alpha: 0.74);
+ final border = colorScheme.outlineVariant.withValues(alpha: 0.34);
+ final duration = widget.disableAnimations
+ ? Duration.zero
+ : const Duration(milliseconds: 200);
+
+ return IgnorePointer(
+ child: AnimatedOpacity(
+ opacity: widget.visible ? 1 : 0,
+ duration: duration,
+ curve: Curves.easeOutCubic,
+ child: AnimatedSlide(
+ offset: widget.visible ? Offset.zero : const Offset(0, -0.18),
+ duration: duration,
+ curve: Curves.easeOutCubic,
+ child: AnimatedScale(
+ scale: widget.visible ? 1 : 0.92,
+ duration: duration,
+ curve: Curves.easeOutBack,
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(30),
+ child: BackdropFilter(
+ filter: ImageFilter.blur(sigmaX: 18, sigmaY: 18),
+ child: AnimatedContainer(
+ duration: duration,
+ curve: Curves.easeOutCubic,
+ width: 164,
+ padding:
+ const EdgeInsets.symmetric(vertical: 7, horizontal: 9),
+ decoration: BoxDecoration(
+ color: surface,
+ borderRadius: BorderRadius.circular(30),
+ border: Border.all(color: border),
+ boxShadow: [
+ BoxShadow(
+ color: accent.withValues(
+ alpha: widget.visible ? 0.24 : 0,
+ ),
+ blurRadius: 32,
+ spreadRadius: 1,
+ ),
+ BoxShadow(
+ color: Colors.black.withValues(alpha: 0.28),
+ blurRadius: 24,
+ offset: const Offset(0, 12),
+ ),
+ ],
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ AnimatedContainer(
+ duration: duration,
+ curve: Curves.easeOutCubic,
+ width: 32,
+ height: 32,
+ decoration: BoxDecoration(
+ color: container.withValues(alpha: 0.92),
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Icon(
+ Icons.speed_rounded,
+ color: onContainer,
+ size: 20,
+ ),
+ ),
+ const SizedBox(width: 9),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ _speedText,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: Theme.of(context)
+ .textTheme
+ .labelLarge
+ ?.copyWith(
+ color: colorScheme.onSurface,
+ fontWeight: FontWeight.w700,
+ ),
+ ),
+ const SizedBox(height: 1),
+ Text(
+ '倍速播放',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: Theme.of(context)
+ .textTheme
+ .bodySmall
+ ?.copyWith(
+ color: colorScheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dart
index c6403229..e484b65b 100644
--- a/lib/pages/player/player_item.dart
+++ b/lib/pages/player/player_item.dart
@@ -126,7 +126,6 @@ class _PlayerItemState extends State<PlayerItem>
Timer? _adjustmentHudHideTimer;
final Set<PlayerPanelHold> _playerPanelHolds = <PlayerPanelHold>{};
PlayerPanelHold? _progressBarDragHold;
- PlayerPanelHold? _horizontalDragHold;
double lastVolume = 0;
@@ -819,7 +818,6 @@ class _PlayerItemState extends State<PlayerItem>
}
_playerPanelHolds.clear();
_progressBarDragHold = null;
- _horizontalDragHold = null;
playerController.panel.canHidePlayerPanel = true;
_startHideTimer();
}
@@ -1938,12 +1936,15 @@ class _PlayerItemState extends State<PlayerItem>
? Container()
: GestureDetector(
onHorizontalDragStart: (_) {
- _horizontalDragHold?.release();
- _horizontalDragHold = acquirePlayerPanelHold();
+ playerController.panel.seekDirection = 0;
},
onHorizontalDragUpdate:
(DragUpdateDetails details) {
playerController.panel.showSeekTime = true;
+ if (details.delta.dx != 0) {
+ playerController.panel.seekDirection =
+ details.delta.dx > 0 ? 1 : -1;
+ }
playerTimer?.cancel();
playerController.pause(enableSync: false);
final double scale =
@@ -1962,11 +1963,10 @@ class _PlayerItemState extends State<PlayerItem>
playerController.play(enableSync: false);
playerController.seek(
playerController.playback.currentPosition);
- _horizontalDragHold?.release();
- _horizontalDragHold = null;
playerTimer?.cancel();
playerTimer = getPlayerTimer();
playerController.panel.showSeekTime = false;
+ playerController.panel.seekDirection = 0;
},
onVerticalDragUpdate:
(DragUpdateDetails details) async {
diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dart
index f835ca61..57bbf0f8 100644
--- a/lib/pages/player/player_item_panel.dart
+++ b/lib/pages/player/player_item_panel.dart
@@ -501,63 +501,28 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
}),
),
Positioned(
- top: 25,
- child: Observer(builder: (context) {
- return playerController.panel.showSeekTime
- ? Wrap(
- alignment: WrapAlignment.center,
- children: <Widget>[
- Container(
- padding: const EdgeInsets.all(8.0),
- decoration: BoxDecoration(
- color: Colors.black54,
- borderRadius: BorderRadius.circular(8.0),
- ),
- child: Text(
- playerController.playback.currentPosition.compareTo(
- playerController
- .playback.playerPosition) >
- 0
- ? '快进 ${playerController.playback.currentPosition.inSeconds - playerController.playback.playerPosition.inSeconds} 秒'
- : '快退 ${playerController.playback.playerPosition.inSeconds - playerController.playback.currentPosition.inSeconds} 秒',
- style: const TextStyle(
- color: Colors.white,
- ),
- ),
- ),
- ],
- )
- : Container();
- })),
+ top: 25,
+ child: Observer(builder: (context) {
+ return PlayerSeekHud(
+ visible: playerController.panel.showSeekTime,
+ currentPosition: playerController.playback.currentPosition,
+ playerPosition: playerController.playback.playerPosition,
+ duration: playerController.playback.duration,
+ direction: playerController.panel.seekDirection,
+ disableAnimations: widget.disableAnimations,
+ );
+ }),
+ ),
Positioned(
- top: 25,
- child: Observer(builder: (context) {
- return playerController.panel.showPlaySpeed
- ? Wrap(
- alignment: WrapAlignment.center,
- children: <Widget>[
- Container(
- padding: const EdgeInsets.all(8.0),
- decoration: BoxDecoration(
- color: Colors.black54,
- borderRadius: BorderRadius.circular(8.0),
- ),
- child: const Row(
- children: <Widget>[
- Icon(Icons.fast_forward, color: Colors.white),
- Text(
- ' 倍速播放',
- style: TextStyle(
- color: Colors.white,
- ),
- ),
- ],
- ),
- ),
- ],
- )
- : Container();
- })),
+ top: 25,
+ child: Observer(builder: (context) {
+ return PlayerSpeedHud(
+ visible: playerController.panel.showPlaySpeed,
+ speed: playerController.playback.playerSpeed,
+ disableAnimations: widget.disableAnimations,
+ );
+ }),
+ ),
Positioned(
top: 25,
child: Observer(builder: (context) {
diff --git a/lib/pages/player/smallest_player_item_panel.dart b/lib/pages/player/smallest_player_item_panel.dart
index 11f2c3bc..db299caf 100644
--- a/lib/pages/player/smallest_player_item_panel.dart
+++ b/lib/pages/player/smallest_player_item_panel.dart
@@ -337,63 +337,28 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
}),
),
Positioned(
- top: 25,
- child: Observer(builder: (context) {
- return playerController.panel.showSeekTime
- ? Wrap(
- alignment: WrapAlignment.center,
- children: <Widget>[
- Container(
- padding: const EdgeInsets.all(8.0),
- decoration: BoxDecoration(
- color: Colors.black54,
- borderRadius: BorderRadius.circular(8.0),
- ),
- child: Text(
- playerController.playback.currentPosition.compareTo(
- playerController
- .playback.playerPosition) >
- 0
- ? '快进 ${playerController.playback.currentPosition.inSeconds - playerController.playback.playerPosition.inSeconds} 秒'
- : '快退 ${playerController.playback.playerPosition.inSeconds - playerController.playback.currentPosition.inSeconds} 秒',
- style: const TextStyle(
- color: Colors.white,
- ),
- ),
- ),
- ],
- )
- : Container();
- })),
+ top: 25,
+ child: Observer(builder: (context) {
+ return PlayerSeekHud(
+ visible: playerController.panel.showSeekTime,
+ currentPosition: playerController.playback.currentPosition,
+ playerPosition: playerController.playback.playerPosition,
+ duration: playerController.playback.duration,
+ direction: playerController.panel.seekDirection,
+ disableAnimations: widget.disableAnimations,
+ );
+ }),
+ ),
Positioned(
- top: 25,
- child: Observer(builder: (context) {
- return playerController.panel.showPlaySpeed
- ? Wrap(
- alignment: WrapAlignment.center,
- children: <Widget>[
- Container(
- padding: const EdgeInsets.all(8.0),
- decoration: BoxDecoration(
- color: Colors.black54,
- borderRadius: BorderRadius.circular(8.0),
- ),
- child: const Row(
- children: <Widget>[
- Icon(Icons.fast_forward, color: Colors.white),
- Text(
- ' 倍速播放',
- style: TextStyle(
- color: Colors.white,
- ),
- ),
- ],
- ),
- ),
- ],
- )
- : Container();
- })),
+ top: 25,
+ child: Observer(builder: (context) {
+ return PlayerSpeedHud(
+ visible: playerController.panel.showPlaySpeed,
+ speed: playerController.playback.playerSpeed,
+ disableAnimations: widget.disableAnimations,
+ );
+ }),
+ ),
Positioned(
top: 25,
child: Observer(builder: (context) {