opt video header

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-06-30 18:40:02 +08:00
parent 0df637fb73
commit ed6353e6d5
8 changed files with 244 additions and 216 deletions

View File

@@ -0,0 +1,59 @@
import 'package:PiliPlus/common/widgets/sliver/sliver_pinned_dynamic_header.dart';
import 'package:PiliPlus/utils/extension/num_ext.dart';
import 'package:flutter/foundation.dart' show clampDouble;
import 'package:flutter/material.dart';
class VideoHeader extends SliverPinnedDynamicHeader {
const VideoHeader({
super.key,
required super.minExtent,
required super.maxExtent,
required this.minVideoHeight,
required this.onScrollRatioChanged,
required super.child,
});
final double minVideoHeight;
final ValueChanged<double> onScrollRatioChanged;
@override
RenderObject createRenderObject(BuildContext context) {
return RenderVideoHeader(
minExtent: minExtent,
maxExtent: maxExtent,
minVideoHeight: minVideoHeight,
onScrollRatioChanged: onScrollRatioChanged,
);
}
}
class RenderVideoHeader extends RenderSliverPinnedDynamicHeader {
RenderVideoHeader({
required super.minExtent,
required super.maxExtent,
required this.minVideoHeight,
required this.onScrollRatioChanged,
});
double? _scrollRatio;
final double minVideoHeight;
final ValueChanged<double> onScrollRatioChanged;
@override
void performLayout() {
super.performLayout();
final scrollOffset = constraints.scrollOffset;
final offset = scrollOffset - (maxExtent - minVideoHeight);
final scrollRatio = clampDouble(
offset.toPrecision(2) / (minVideoHeight - kToolbarHeight).toPrecision(2),
0.0,
1.0,
);
if (_scrollRatio != scrollRatio) {
_scrollRatio = scrollRatio;
WidgetsBinding.instance.addPostFrameCallback((_) {
onScrollRatioChanged(scrollRatio);
});
}
}
}