letsar /flutter_sticky_header
Flutter implementation of sticky headers for sliver
★ 998⑂ 183👁 13⑃ 32● 94▤ 5
+0
日增长
998
stars
183
forks
13
watchers
32
prs
94
issues
5
releases
README
flutter_sticky_header
A Flutter implementation of sticky headers with a sliver as a child.
!Screenshot
Features
Accepts one sliver as content.
Header can overlap its sliver (useful for sticky side header for example).
Notifies when the header scrolls outside the viewport.
Can scroll in any direction.
Supports overlapping (AppBars for example).
Supports not sticky headers (with sticky: false parameter).
Supports a controller which notifies the scroll offset of the current sticky header.
Notifies when the state of a header changes (with the onStateChanged parameter).
Supports headers at the end of their sliver, such as date headers in a reversed chat list or sticky footers (with the stickToEnd parameter).
Do you need this package?
Since Flutter 3.13, you can create simple sticky headers with the framework alone: put a pinned header (for example a PinnedHeaderSliver, available since Flutter 3.24) and the content in a SliverMainAxisGroup. The header stays pinned until the end of its group:
dart
CustomScrollView(
slivers: [
SliverMainAxisGroup(
slivers: [
PinnedHeaderSliver(child: Header()),
SliverList.builder(itemBuilder: ...),
],
),
],
)
This package is still useful if you need:
a header that overlaps its content, for example sticky side headers (overlapsContent);
a header built from its state, whether it is pinned and how much it is scrolled out (SliverStickyHeader.builder), or notified when this state changes (onStateChanged);
the scroll offset of the current sticky header (StickyHeaderController);
a header at the end of its sliver, sticking to the end of the viewport (stickToEnd), for example in a reversed list.
Getting started
In the pubspec.yaml of your flutter project, add the following dependency:
yaml
dependencies:
...
flutter_sticky_header:
In your library add the following import:
dart
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
For help getting started with Flutter, view the online documentation.
SliverStickyHeader
You can place one or multiple SliverStickyHeaders inside a CustomScrollView.
dart
SliverStickyHeader(
header: Container(
height: 60.0,
color: Colors.lightBlue,
padding: EdgeInsets.symmetric(horizontal: 16.0),
alignment: Alignment.centerLeft,
child: Text(
'Header 0',
style: const TextStyle(color: Colors.white),
),
),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) = ListTile(
leading: CircleAvatar(
child: Text('0'),
),
title: Text('List tile $i'),
),
childCount: 4,
),
),
);
SliverStickyHeader.builder
If you want to change the header layout during its scroll, you can use the SliverStickyHeader.builder constructor.
The example belows changes the opacity of the header as it scrolls off the viewport.
dart
SliverStickyHeader.builder(
builder: (context, state) = Container(
Top issues
#79Can't tap TextField in sticky header4 comments · 2022-07-27#56scrollPercentage only 0 or 13 comments · 2021-01-23#111Performance lag with flutter_sticky_header on Flutter 3.32.81 comments · 2025-08-08#105How can I stop jumping on the bottom of the screen?1 comments · 2025-01-14
Latest release
v0.4.0 v0.4.0 2019-05-230.4.0 Updated SDK constraint to support new error message formats. Updated error message formats