From bfa0741c7a43543f491fe807a9b8b3390f824a07 Mon Sep 17 00:00:00 2001 From: Elias Bonnici Date: Fri, 10 Jan 2025 09:48:03 +0100 Subject: [PATCH] Use `PinnedHeaderSliver` instead of `SliverPersistentHeader` Using PinnedHeaderSliver removes the need for creating a SliverPersistentHeaderDelegate and predicting the header's size. --- lib/app/views/app_page.dart | 44 +++++++------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/lib/app/views/app_page.dart b/lib/app/views/app_page.dart index bd309567f..dd3f6ee39 100755 --- a/lib/app/views/app_page.dart +++ b/lib/app/views/app_page.dart @@ -463,20 +463,15 @@ class _AppPageState extends ConsumerState { slivers: [ SliverMainAxisGroup( slivers: [ - SliverPersistentHeader( - pinned: true, - delegate: _SliverTitleDelegate( - child: ColoredBox( - color: Theme.of(context).colorScheme.surface, - child: Padding( - key: _sliverTitleWrapperGlobalKey, - padding: const EdgeInsets.only( - left: 18.0, right: 18.0, bottom: 12.0, top: 4.0), - child: _buildTitle(context), - ), + PinnedHeaderSliver( + child: ColoredBox( + color: Theme.of(context).colorScheme.surface, + child: Padding( + key: _sliverTitleWrapperGlobalKey, + padding: const EdgeInsets.only( + left: 18.0, right: 18.0, bottom: 12.0, top: 4.0), + child: _buildTitle(context), ), - // Header height = title height + vertical padding - height: _getTitleHeight(context) + 16, ), ), if (widget.headerSliver != null) @@ -1021,29 +1016,6 @@ class _VisibilityListenerState extends State<_VisibilityListener> { } } -class _SliverTitleDelegate extends SliverPersistentHeaderDelegate { - _SliverTitleDelegate({ - required this.height, - required this.child, - }); - final double height; - final Widget child; - - @override - double get minExtent => height; - @override - double get maxExtent => height; - - @override - Widget build( - BuildContext context, double shrinkOffset, bool overlapsContent) { - return child; - } - - @override - bool shouldRebuild(_SliverTitleDelegate oldDelegate) => true; -} - class _NoImplicitScrollPhysics extends ScrollPhysics { const _NoImplicitScrollPhysics({super.parent});