搜索插件、代码仓与 APP 分类

flutter_sticky_header 封面
插件详情v0.8.0

flutter_sticky_header

Flutter 中的粘性标题实现为一个滑动条。在 CustomScrollView 中使用它。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
30.6万
喜欢数
943
Pub 分数
150

安装插件

flutter pub add flutter_sticky_header

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,使用滑块在 CustomScrollView 中实现粘性标题。它允许标题在用户滚动列表或网格时保持在可滚动内容的顶部,从而增强导航和视觉组织。非常适合具有分组项目的长列表,例如联系人、消息或分类数据。该包轻量级、文档完善,并可在所有主要平台上兼容。

适合场景

  • 分组列表视图
  • 带字母标题的联系人列表
  • 带日期标题的消息线程
  • 分类产品列表
  • 可滚动的仪表板,带部分标题

主要特点

  • 基于 Sliver 的实现
  • 自动标题固定
  • 可自定义的标题样式
  • 平滑滚动行为
  • 跨平台支持
  • 与 CustomScrollView 的轻松集成

适合对象

  • 开发带有部分的可滚动列表的开发者
  • 需要视觉化组织内容的应用程序
  • 需要性能优化的标头的项目
  • 优先考虑平台一致性的团队

使用建议

  • 需要在 CustomScrollView 内使用
  • 复杂标题可能需要额外的布局调整
  • 不适用于非 Sliver 滚动上下文
  • 超出基础样式的定制功能有限
  • 处理超大数据集时的性能影响

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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

:clap: 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.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目