perf/chapter sheet
This commit is contained in:
1 parent
5b211965bc
commit
107269f07d
1 file changed
+38
-24
@@ -311,12 +311,27 @@ class _VideoChaptersSheetState extends ConsumerState<VideoChaptersSheet> {
|
||||
final _scrollController = ScrollController();
|
||||
final _prototypeKey = GlobalKey();
|
||||
final _showSyncButton = ValueNotifier(false);
|
||||
late final _selectedIndex = ValueNotifier(_chapterIndex(_position));
|
||||
Listenable? _controller;
|
||||
bool _syncVisibilityScheduled = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scrollController.addListener(_scheduleSyncVisibility);
|
||||
ref.listenManual(myVideoPlayerControllerProvider, (_, next) {
|
||||
_controller?.removeListener(_updateSelectedIndex);
|
||||
_controller = next?..addListener(_updateSelectedIndex);
|
||||
_updateSelectedIndex();
|
||||
}, fireImmediately: true);
|
||||
ref.listenManual(
|
||||
chromecastCurrentPositionProvider,
|
||||
(_, _) => _updateSelectedIndex(),
|
||||
);
|
||||
ref.listenManual(
|
||||
chromecastHasConnectedSessionProvider,
|
||||
(_, _) => _updateSelectedIndex(),
|
||||
);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) _syncToVideo(animate: false);
|
||||
});
|
||||
@@ -324,8 +339,10 @@ class _VideoChaptersSheetState extends ConsumerState<VideoChaptersSheet> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller?.removeListener(_updateSelectedIndex);
|
||||
_scrollController.dispose();
|
||||
_showSyncButton.dispose();
|
||||
_selectedIndex.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -338,6 +355,13 @@ class _VideoChaptersSheetState extends ConsumerState<VideoChaptersSheet> {
|
||||
(chapter) => chapter.timecode <= position.inSeconds,
|
||||
);
|
||||
|
||||
void _updateSelectedIndex() {
|
||||
final index = _chapterIndex(_position);
|
||||
if (index == _selectedIndex.value) return;
|
||||
_selectedIndex.value = index;
|
||||
_scheduleSyncVisibility();
|
||||
}
|
||||
|
||||
double? get _syncOffset {
|
||||
if (!_scrollController.hasClients ||
|
||||
!_scrollController.position.hasContentDimensions) {
|
||||
@@ -345,7 +369,7 @@ class _VideoChaptersSheetState extends ConsumerState<VideoChaptersSheet> {
|
||||
}
|
||||
final itemHeight = _prototypeKey.currentContext?.size?.height;
|
||||
if (itemHeight == null) return null;
|
||||
final index = _chapterIndex(_position);
|
||||
final index = _selectedIndex.value;
|
||||
final maxOffset =
|
||||
(widget.chapters.length * itemHeight -
|
||||
_scrollController.position.viewportDimension)
|
||||
@@ -420,33 +444,23 @@ class _VideoChaptersSheetState extends ConsumerState<VideoChaptersSheet> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isCasting = ref.watch(chromecastHasConnectedSessionProvider);
|
||||
if (isCasting) ref.watch(chromecastCurrentPositionProvider);
|
||||
final controller = ref.watch(myVideoPlayerControllerProvider);
|
||||
return ListenableBuilder(
|
||||
listenable: Listenable.merge([
|
||||
if (!isCasting && controller != null) controller,
|
||||
]),
|
||||
builder: (context, _) => _buildPanel(_position),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPanel(Duration position) {
|
||||
_scheduleSyncVisibility();
|
||||
final selectedIndex = _chapterIndex(position);
|
||||
final slivers = <Widget>[
|
||||
if (widget.chapters.isNotEmpty)
|
||||
SliverPrototypeExtentList(
|
||||
prototypeItem: SizedBox(
|
||||
key: _prototypeKey,
|
||||
child: _chapterTile(widget.chapters.first, prototype: true),
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) => _chapterTile(
|
||||
widget.chapters[index],
|
||||
selected: index == selectedIndex,
|
||||
ValueListenableBuilder<int>(
|
||||
valueListenable: _selectedIndex,
|
||||
builder: (context, selectedIndex, _) => SliverPrototypeExtentList(
|
||||
prototypeItem: SizedBox(
|
||||
key: _prototypeKey,
|
||||
child: _chapterTile(widget.chapters.first, prototype: true),
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) => _chapterTile(
|
||||
widget.chapters[index],
|
||||
selected: index == selectedIndex,
|
||||
),
|
||||
childCount: widget.chapters.length,
|
||||
),
|
||||
childCount: widget.chapters.length,
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
|
||||
Reference in new issue
Block a user