• Stars
    star
    880
  • Rank 51,881 (Top 2 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flutter implementation of sticky headers for sliver

flutter_sticky_header

A Flutter implementation of sticky headers with a sliver as a child.

Pub Donate

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.

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  flutter_sticky_header:

In your library add the following import:

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.

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.

SliverStickyHeader.builder(
  builder: (context, state) => Container(
        height: 60.0,
        color: (state.isPinned ? Colors.pink : Colors.lightBlue)
            .withOpacity(1.0 - state.scrollPercentage),
        padding: EdgeInsets.symmetric(horizontal: 16.0),
        alignment: Alignment.centerLeft,
        child: Text(
          'Header #1',
          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,
    ),
  ),
);

You can find more examples in the Example project.

Sponsoring

I'm working on my packages on my free-time, but I don't have as much time as I would. If this package or any other package I created is helping you, please consider to sponsor me. By doing so, I will prioritize your issues or your pull-requests before the others.

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a new feature, please send a pull request.

Thanks

👏 Thanks to slightfoot with it's RenderBox version (https://github.com/slightfoot/flutter_sticky_headers) which unintentionally challenged me to work in this RenderSliver version.

More Repositories

1

flutter_staggered_grid_view

A Flutter staggered grid view
Dart
3,043
star
2

flutter_slidable

A Flutter implementation of slidable list item with directional slide actions.
Dart
2,695
star
3

flutter_sidekick

Widgets for creating Hero-like animations between two widgets within the same screen.
Dart
294
star
4

local_hero

A widget which implicitly launches a hero animation when its position changed within the same route.
Dart
204
star
5

gap

Flutter widgets for easily adding gaps inside Flex widgets such as Columns and Rows or scrolling views
Dart
193
star
6

binder

A lightweight, yet powerful way to bind your application state with your business logic.
Dart
177
star
7

flutter_counter_challenge_2020

A set of counter apps made for #FlutterCounterChallenge2020
Dart
174
star
8

overflow_view

A widget displaying children in a line until there is not enough space and showing a the number of children not rendered.
Dart
170
star
9

nil

A simple Flutter widget to add in the widget tree when you want to show nothing, with minimal impact on performance.
Dart
152
star
10

RestLess

The automatic type-safe-reflectionless REST API client library for .Net Standard
C#
110
star
11

flutter_parallax

A Flutter widget that moves according to a scroll controller.
Dart
100
star
12

flutter_scatter

A widget that displays a collection of dispersed and non-overlapping children
Dart
91
star
13

visual_effect

VisualEffect API for Flutter
Dart
70
star
14

polygon

A simple way to draw polygon shapes and to clip them
Dart
62
star
15

maestro

A way to compose your app's state and to expose your data across your entire Flutter application.
Dart
47
star
16

atomized_image

A widget which paints and animates images with particles to achieve an atomized effect
Dart
40
star
17

hashwag

Flutter app that showcases some hashtags
Dart
25
star
18

value_layout_builder

A LayoutBuilder with an extra value
Dart
17
star
19

state_watcher

A simple, yet powerful reactive state management solution for Flutter applications
Dart
15
star
20

DoLess.UriTemplates

.Net Standard implementation of the URI Template Spec https://tools.ietf.org/html/rfc6570
C#
14
star
21

flutter-binder-snippets

Quick and easy Binder snippets
13
star
22

flutter_puzzle_hack

Dart
10
star
23

dash_punk

Dart
6
star
24

letsar

My profile
5
star
25

DoLess.Commands

Commands for Mvvm
C#
4
star
26

DoLess.Bindings

C#
3
star
27

DoLess.Localization

A simple way to share localization files (resx) from cross-platform lib to iOS and Android libs
C#
3
star
28

letsar.github.io

JavaScript
2
star
29

RestLess.JsonNet

Json formatters for RestLess using Json.Net
C#
1
star
30

adventofcode_2021

Dart
1
star