Vaani/lib/features/player/view/widgets/player_progress_bar.dart

67 lines
2.2 KiB
Dart
Raw Normal View History

2025-11-13 17:53:23 +08:00
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
2025-11-22 15:54:29 +08:00
import 'package:vaani/constants/sizes.dart';
2025-12-08 17:54:08 +08:00
import 'package:vaani/features/player/providers/abs_provider.dart';
2026-01-13 11:56:49 +08:00
import 'package:vaani/features/settings/app_settings_provider.dart';
2025-11-13 17:53:23 +08:00
2026-01-13 11:56:49 +08:00
/// 进度条展示 根据设置显示章节进度或整本书的进度
class AbsDesktopProgressBar extends HookConsumerWidget {
2026-01-06 17:57:51 +08:00
final TimeLabelLocation timeLabelLocation;
2026-01-13 11:56:49 +08:00
const AbsDesktopProgressBar({
2025-11-13 17:53:23 +08:00
super.key,
2026-01-06 17:57:51 +08:00
this.timeLabelLocation = TimeLabelLocation.below,
2025-11-13 17:53:23 +08:00
});
@override
Widget build(BuildContext context, WidgetRef ref) {
2025-12-12 15:38:47 +08:00
final player = ref.watch(absPlayerProvider);
2025-11-22 15:54:29 +08:00
final currentChapter = ref.watch(currentChapterProvider);
2026-01-13 11:56:49 +08:00
final playerSettings =
ref.watch(appSettingsProvider.select((v) => v.playerSettings));
final showChapterProgress =
playerSettings.expandedPlayerSettings.showChapterProgress;
2025-11-13 17:53:23 +08:00
2026-01-13 11:56:49 +08:00
final position = ref.watch(progressProvider);
final buffered = ref.watch(progressBufferedProvider);
2025-11-13 17:53:23 +08:00
2026-01-13 11:56:49 +08:00
final total = ref.watch(totalProvider);
2025-11-13 17:53:23 +08:00
return ProgressBar(
2026-01-13 11:56:49 +08:00
progress: position.requireValue,
2025-12-18 16:46:25 +08:00
total: total,
2025-11-13 17:53:23 +08:00
onSeek: (duration) {
player.seekInBook(
2026-01-13 11:56:49 +08:00
duration +
(showChapterProgress
? (currentChapter?.start ?? Duration.zero)
: Duration.zero),
2025-11-13 17:53:23 +08:00
);
},
thumbRadius: 8,
2026-01-13 11:56:49 +08:00
buffered: buffered.requireValue,
2025-11-13 17:53:23 +08:00
bufferedBarColor: Theme.of(context).colorScheme.secondary,
timeLabelType: TimeLabelType.remainingTime,
2026-01-06 17:57:51 +08:00
timeLabelLocation: timeLabelLocation,
2025-11-13 17:53:23 +08:00
);
}
}
2026-01-06 17:57:51 +08:00
// 书籍进度 简化版
2026-01-13 11:56:49 +08:00
class AbsMinimizedProgress extends HookConsumerWidget {
const AbsMinimizedProgress({super.key});
2025-11-13 17:53:23 +08:00
@override
Widget build(BuildContext context, WidgetRef ref) {
2026-01-13 11:56:49 +08:00
final position = ref.watch(progressProvider);
final total = ref.watch(totalProvider);
2025-11-22 15:54:29 +08:00
return SizedBox(
2026-01-13 11:56:49 +08:00
height: AppElementSizes.barHeight,
2025-11-22 15:54:29 +08:00
child: LinearProgressIndicator(
2026-01-13 11:56:49 +08:00
value: total > Duration.zero
? ((position.value ?? Duration.zero).inSeconds / total.inSeconds)
: 0,
2025-11-22 15:54:29 +08:00
),
2025-11-13 17:53:23 +08:00
);
}
}