搜尋套件、儲存庫與 APP 分類

sticky_and_expandable_list 封面
套件詳情v1.1.3

sticky_and_expandable_list

建構一個分組列表,支援展開/摺疊區段和黏滯標題,並支援與滑動條組件一起使用。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
7820
喜歡數
175
Pub 分數
140

安裝套件

flutter pub add sticky_and_expandable_list

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,可建立具有可摺疊區段與黏性標題的群組清單,非常適合以層次結構組織內容。它與 Sliver 小部件無縫整合,適用於自訂捲動檢視(如 CustomScrollView)。此套件支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 與 Linux,為各裝置提供一致的體驗。它透過最少的樣板程式碼簡化複雜的清單互動。

適用情境

  • 分組資料顯示
  • 可摺疊部分清單
  • 黏性標題導航
  • 自定義滾動視圖
  • 動態內容組織
  • 長列表的增強使用者介面

主要特色

  • 可展開/可收合區段
  • 黏性章節標題
  • Sliver 小部件相容性
  • 跨平台支援
  • 所需的設定最少
  • 平滑動畫

適合對象

  • 開發複雜清單的開發者
  • 需要互動式佈局的UI設計師
  • 具有層級資料的應用程式
  • 帶標題的可滾動介面
  • 行動與Web應用程式

使用建議

  • 需要了解 Sliver 小部件
  • 在非常大的資料集上可能會影響效能
  • 超出基本樣式之外的自訂功能有限
  • 最適合中等規模的分組資料
  • 不建議用於簡單的扁平清單

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

sticky_and_expandable_list

Flutter implementation of sticky headers and expandable list.Support use it in a CustomScrollView.

Pub README i18n:中文说明

Screenshot

Features

  • Build a grouped list, which support expand/collapse section and sticky header.
  • Use it with CustomScrollView、SliverAppBar.
  • Listen the scroll offset of current sticky header, current sticky header index and switching header index.
  • Only use one list widget, so it supports large data and a normal memory usage.
  • More section customization support, you can return a new section widget by sectionBuilder, to customize background,expand/collapse animation, section layout, and so on.
  • Support add divider.
  • Support overlap content.
  • Support scroll to index like ListView, by scroll-to-index.
  • Pull to refresh and load more, by pull_to_refresh.

Getting Started

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

dependencies:
  sticky_and_expandable_list: ^1.1.3

Basic Usage

sectionList is a custom data source for ExpandableListView. We should create a model list to store the information of each section, the model must implement ExpandableListSection.

    //In this example, we create a custom model class(ExampleSection).
    //class ExampleSection implements ExpandableListSection<String> {}
    //so: SliverExpandableChildDelegate<String, ExampleSection>()
    List<ExampleSection> sectionList = List<ExampleSection>();
    return ExpandableListView(
      builder: SliverExpandableChildDelegate<String, ExampleSection>(
          sectionList: sectionList,
          headerBuilder: (context, sectionIndex, index) =>
              Text("Header #$sectionIndex"),
          itemBuilder: (context, sectionIndex, itemIndex, index) {
            String item = sectionList[sectionIndex].items[itemIndex];
            return ListTile(
              leading: CircleAvatar(
                child: Text("$index"),
              ),
              title: Text(item),
            );
          }),
    );

Detail Examples

If you want to use it with sliver widget, use SliverExpandableList instead of ExpandableListView.

FAQ

How to expand/collapse item?
setState(() {
  sectionList[i].setSectionExpanded(true);
});

Example

How to listen current sticky header or the sticky header scroll offset?
  @override
  Widget build(BuildContext context) {
    ExpandableListView(
      builder: SliverExpandableChildDelegate<String, ExampleSection>(
        headerController: _getHeaderController(),
      ),
    )
  }

  _getHeaderController() {
    var controller = ExpandableListController();
    controller.addListener(() {
      print("switchingSectionIndex:${controller.switchingSectionIndex}, stickySectionIndex:" +
          "${controller.stickySectionIndex},scrollPercent:${controller.percent}");
    });
    return controller;
  }
How to set background for each section?

Use sectionBuilder

Customize expand/collapse animation support?

Example

Change Log

CHANGELOG

所屬分類

原始碼儲存庫

使用此套件的專案