Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky headers on SliverList

Tags:

flutter

I've seen new flutter video and seen some interesting. (It's not typical sticky header or expandable list, so I don't know how to name it)

Video - watch from 0:20

Does anybody know how can I create such type of list with headers using SliverList?

enter image description here

like image 547
Andrey Turkovsky Avatar asked Oct 31 '18 14:10

Andrey Turkovsky


1 Answers

SliverPersistentHeader is the more generic widget behind SliverAppBar that you can use.

SliverPersistentHeader(
    delegate: SectionHeaderDelegate("Section B"),
    pinned: true,
),

And the SectionHeaderDelegate can be implement with something like:

class SectionHeaderDelegate extends SliverPersistentHeaderDelegate {
  final String title;
  final double height;

  SectionHeaderDelegate(this.title, [this.height = 50]);

  @override
  Widget build(context, double shrinkOffset, bool overlapsContent) {
    return Container(
      color: Theme.of(context).primaryColor,
      alignment: Alignment.center,
      child: Text(title),
    );
  }

  @override
  double get maxExtent => height;

  @override
  double get minExtent => height;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => false;
}
like image 111
user1032613 Avatar answered Oct 21 '22 01:10

user1032613