Files
SpotiFLAC-Mobile/lib/controllers/collapsing_header_scroll_mixin.dart
T
zarzet cc0e55b078 perf(collection): decode the blurred header backdrop small
Material album, playlist and local album headers decoded their blurred
backdrop at full cover size. It now uses the small decode the track
details backdrop already has. The stretch of the header artwork rebuilds
only while the list is pulled past its start, header title heights are
remembered, the quality the songs of an album share is worked out once
per song list, and the collapsing header reads its expanded height once
per layout change instead of on every scroll report.
2026-11-21 22:06:24 +07:00

48 lines
1.5 KiB
Dart

import 'package:material_ui/material_ui.dart';
/// Expanded height of the album-style collapsing header, shared with the
/// loading screens that show the same header before the tracks arrive.
double collectionHeaderExpandedHeight(BuildContext context) {
final mediaSize = MediaQuery.sizeOf(context);
return (mediaSize.height * 0.6).clamp(400.0, 580.0);
}
/// Shared collapsing-header scroll behavior for album-style screens: owns the
/// [ScrollController] and flips [showTitleNotifier] once the header has
/// scrolled out of view.
mixin CollapsingHeaderScrollMixin<T extends StatefulWidget> on State<T> {
final ScrollController scrollController = ScrollController();
final ValueNotifier<bool> showTitleNotifier = ValueNotifier(false);
double? _cachedExpandedHeight;
@override
void initState() {
super.initState();
scrollController.addListener(_onHeaderScroll);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_cachedExpandedHeight = calculateExpandedHeight(context);
}
@override
void dispose() {
scrollController.removeListener(_onHeaderScroll);
scrollController.dispose();
showTitleNotifier.dispose();
super.dispose();
}
double calculateExpandedHeight(BuildContext context) =>
collectionHeaderExpandedHeight(context);
void _onHeaderScroll() {
final expandedHeight =
_cachedExpandedHeight ?? calculateExpandedHeight(context);
showTitleNotifier.value =
scrollController.offset > (expandedHeight - kToolbarHeight - 20);
}
}