opt floating header

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-03-05 11:31:44 +08:00
parent b61a54bf9b
commit 9b145b525a

View File

@@ -28,10 +28,10 @@ class SliverFloatingHeaderWidget extends SingleChildRenderObjectWidget {
const SliverFloatingHeaderWidget({ const SliverFloatingHeaderWidget({
super.key, super.key,
required Widget super.child, required Widget super.child,
this.backgroundColor, required this.backgroundColor,
}); });
final Color? backgroundColor; final Color backgroundColor;
@override @override
RenderObject createRenderObject(BuildContext context) => RenderObject createRenderObject(BuildContext context) =>
@@ -48,11 +48,11 @@ class SliverFloatingHeaderWidget extends SingleChildRenderObjectWidget {
class RenderSliverFloatingHeader extends RenderSliverSingleBoxAdapter { class RenderSliverFloatingHeader extends RenderSliverSingleBoxAdapter {
RenderSliverFloatingHeader({ RenderSliverFloatingHeader({
required Color? backgroundColor, required Color backgroundColor,
}) : _backgroundColor = backgroundColor; }) : _backgroundColor = backgroundColor;
Color? _backgroundColor; Color _backgroundColor;
set backgroundColor(Color? value) { set backgroundColor(Color value) {
if (_backgroundColor == value) return; if (_backgroundColor == value) return;
_backgroundColor = value; _backgroundColor = value;
markNeedsPaint(); markNeedsPaint();
@@ -135,19 +135,23 @@ class RenderSliverFloatingHeader extends RenderSliverSingleBoxAdapter {
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (child != null && geometry!.visible) { if (child != null && geometry!.visible) {
offset += Offset(0.0, childMainAxisPosition(child!)); offset += Offset(0.0, childMainAxisPosition(child!));
if (_backgroundColor != null) { final size = child!.size;
final size = child!.size; context.canvas.drawRect(
context.canvas.drawRect( Rect.fromLTWH(
Rect.fromLTWH( offset.dx,
offset.dx, offset.dy - 2,
offset.dy - 2, size.width,
size.width, size.height + 2,
size.height + 2, ),
), Paint()..color = _backgroundColor,
Paint()..color = _backgroundColor!, );
);
}
context.paintChild(child!, offset); context.paintChild(child!, offset);
} }
} }
@override
bool hitTestSelf({
required double mainAxisPosition,
required double crossAxisPosition,
}) => true;
} }