Sheets rendered at the host's maximum height regardless of content, so a one-item player queue or a two-track picker filled ~75% of a desktop window with empty space. BottomSheetPageScaffold now always lays out Column(mainAxisSize: .min) plus Flexible(child:), and each sheet body shrink-wraps its own scrollable. The scaffold's shrinkWrap flag is gone: its old true branch put the child on an unbounded axis, where an over-tall list overflowed instead of clamping and scrolling. Measured on a 1600x1000 window, the chapter sheet goes from 750px to 118px for one chapter and the two-column track sheet from 750px to 154px for one audio and one subtitle track, both still clamping at the cap. Add SheetSplitColumns for the three side-by-side sheet layouts. A bare VerticalDivider has no intrinsic height, so it inflated those rows to the cap on its own; the rule now paints from a Positioned.fill that cannot size the Stack. IntrinsicHeight is not an option because a Viewport has no intrinsics. Because sheets are bottom-anchored, a content-driven height moves the sheet's top edge and everything above the change point. Three surfaces opt out for that reason and say so at the call site: SubtitleSearchSheet and its language picker keep filling, since both refilter under an autofocused field; FiltersBottomSheet holds the outgoing page's height through its loading transient; and RatingBottomSheet no longer hides MAL/AniList rows asynchronously, which used to slide live rating controls down two rows several hundred ms after open. Wrap the shared StateMessageWidget at the filters sheet boundary rather than editing a widget with 33 filling call sites. The host gains an AnimatedSize keyed per sheet session so nested pushes ease while a replacing show adopts its own height, a 720px absolute height ceiling on desktop windows only, and a min(max(25%, 96px), 60%) drag-dismiss threshold so short sheets neither close on a nudge nor become undismissable. Add videoControls.noAudioDevicesAvailable so the audio output page shows a placeholder instead of a bare header while devices load.
180 lines
6.6 KiB
Dart
180 lines
6.6 KiB
Dart
import 'dart:async' show Stream, unawaited;
|
|
import '../../../media/ids.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:plezy/widgets/app_icon.dart';
|
|
import 'package:material_symbols_icons/symbols.dart';
|
|
|
|
import '../../../i18n/strings.g.dart';
|
|
import '../../../media/media_server_client.dart';
|
|
import '../../../mpv/mpv.dart';
|
|
import '../../../services/download_storage_service.dart';
|
|
import '../../../media/media_source_info.dart';
|
|
import '../../../theme/mono_tokens.dart';
|
|
import '../../../utils/formatters.dart';
|
|
import '../../../utils/player_utils.dart';
|
|
import '../../../utils/provider_extensions.dart';
|
|
import '../../../utils/scroll_utils.dart';
|
|
import '../../../widgets/focusable_list_tile.dart';
|
|
import '../../../widgets/overlay_sheet.dart';
|
|
import '../widgets/media_selector_thumbnail.dart';
|
|
import 'base_video_control_sheet.dart';
|
|
import '../../optimized_media_image.dart';
|
|
|
|
/// Bottom sheet for selecting chapters
|
|
class ChapterSheet extends StatefulWidget {
|
|
final Player player;
|
|
final List<MediaChapter> chapters;
|
|
final bool chaptersLoaded;
|
|
final bool canControl;
|
|
final String? serverId; // Server ID for the metadata these chapters belong to
|
|
final Future<void> Function(Duration position)? onSeekRequested;
|
|
final Function(Duration position)? onSeekCompleted;
|
|
|
|
const ChapterSheet({
|
|
super.key,
|
|
required this.player,
|
|
required this.chapters,
|
|
required this.chaptersLoaded,
|
|
required this.canControl,
|
|
this.serverId,
|
|
this.onSeekRequested,
|
|
this.onSeekCompleted,
|
|
});
|
|
|
|
@override
|
|
State<ChapterSheet> createState() => _ChapterSheetState();
|
|
}
|
|
|
|
class _ChapterSheetState extends State<ChapterSheet> {
|
|
final _initialScroll = InitialItemScrollController();
|
|
late Stream<int?> _chapterIndexStream;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_bindChapterIndexStream();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(ChapterSheet oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (!identical(oldWidget.player, widget.player) || !identical(oldWidget.chapters, widget.chapters)) {
|
|
_bindChapterIndexStream();
|
|
}
|
|
}
|
|
|
|
void _bindChapterIndexStream() {
|
|
_chapterIndexStream = widget.player.streams.position
|
|
.map((position) => MediaChapter.indexAtPosition(position, widget.chapters))
|
|
.distinct();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_initialScroll.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _handleChapterTap(Duration position) async {
|
|
if (!widget.canControl) return;
|
|
final clamped = clampSeekPosition(widget.player, position);
|
|
await (widget.onSeekRequested ?? widget.player.seek)(clamped);
|
|
if (mounted) {
|
|
widget.onSeekCompleted?.call(clamped);
|
|
OverlaySheetController.of(context).close();
|
|
}
|
|
}
|
|
|
|
/// Get the media client for chapters, or null if unavailable (offline mode).
|
|
MediaServerClient? _tryGetClientForChapters(BuildContext context) {
|
|
return context.tryGetMediaClientForServer(serverIdOrNull(widget.serverId));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return StreamBuilder<int?>(
|
|
stream: _chapterIndexStream,
|
|
initialData: MediaChapter.indexAtPosition(widget.player.state.position, widget.chapters),
|
|
builder: (context, chapterSnapshot) {
|
|
final currentChapterIndex = chapterSnapshot.data;
|
|
Widget content;
|
|
if (!widget.chaptersLoaded) {
|
|
content = const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 32),
|
|
child: Center(heightFactor: 1, child: CircularProgressIndicator()),
|
|
);
|
|
} else if (widget.chapters.isEmpty) {
|
|
content = Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 32),
|
|
child: Center(
|
|
heightFactor: 1,
|
|
child: Text(t.videoControls.noChaptersAvailable, style: TextStyle(color: tokens(context).textMuted)),
|
|
),
|
|
);
|
|
} else {
|
|
_initialScroll.maybeScrollTo(currentChapterIndex);
|
|
|
|
content = ListView.builder(
|
|
shrinkWrap: true,
|
|
controller: _initialScroll.controller,
|
|
itemCount: widget.chapters.length,
|
|
itemBuilder: (context, index) {
|
|
final chapter = widget.chapters[index];
|
|
final isCurrentChapter = currentChapterIndex == index;
|
|
|
|
final localThumbPath = widget.serverId != null && chapter.thumb != null
|
|
? DownloadStorageService.instance.getArtworkPathSync(ServerId(widget.serverId!), chapter.thumb!)
|
|
: null;
|
|
|
|
return FocusableListTile(
|
|
key: index == 0 ? _initialScroll.firstItemKey : null,
|
|
leading: chapter.thumb != null
|
|
? MediaSelectorThumbnail(
|
|
width: 60,
|
|
height: 34,
|
|
thumbnail: OptimizedMediaImage.thumb(
|
|
client: _tryGetClientForChapters(context),
|
|
imagePath: chapter.thumb,
|
|
localFilePath: localThumbPath,
|
|
width: 60,
|
|
height: 34,
|
|
fit: BoxFit.cover,
|
|
errorWidget: (context, url, error) =>
|
|
const AppIcon(Symbols.image_rounded, fill: 1, color: Colors.white54, size: 34),
|
|
),
|
|
isCurrent: isCurrentChapter,
|
|
borderColor: Theme.of(context).colorScheme.primary,
|
|
)
|
|
: null,
|
|
title: Text(
|
|
chapter.label,
|
|
style: TextStyle(
|
|
color: isCurrentChapter ? Theme.of(context).colorScheme.primary : null,
|
|
fontWeight: isCurrentChapter ? FontWeight.bold : FontWeight.normal,
|
|
),
|
|
),
|
|
subtitle: Text(
|
|
formatDurationTimestamp(chapter.startTime),
|
|
style: TextStyle(
|
|
color: isCurrentChapter
|
|
? Theme.of(context).colorScheme.primary.withValues(alpha: 0.7)
|
|
: tokens(context).textMuted,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
trailing: isCurrentChapter
|
|
? AppIcon(Symbols.play_circle_rounded, fill: 1, color: Theme.of(context).colorScheme.primary)
|
|
: null,
|
|
onTap: widget.canControl ? () => unawaited(_handleChapterTap(chapter.startTime)) : null,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
return BaseVideoControlSheet(title: t.videoControls.chapters, icon: Symbols.bookmarks_rounded, child: content);
|
|
},
|
|
);
|
|
}
|
|
}
|