搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案