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

grouped_list 封面
插件详情v6.0.0

grouped_list

一个 Flutter ListView,其中列表项可以分组为多个部分。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
16.2万
喜欢数
1620
Pub 分数
150

安装插件

flutter pub add grouped_list

插件介绍

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

一个 Flutter 包,可创建将项目组织成可折叠或不可折叠部分的 ListView。它通过允许开发者定义组标题并高效管理项目分组逻辑,简化了分组数据的显示。适用于联系人、日历或分类内容等列表,支持自定义样式和动态更新。该包轻量级,并可在所有主要平台上无缝集成到现有的 Flutter 应用中。

适合场景

  • 显示分类联系人
  • 显示基于时间的事件列表
  • 创建可折叠的产品类别
  • 按日期整理用户生成的内容
  • 构建结构化导航菜单

主要特点

  • 支持部分标题
  • 允许折叠组
  • 可自定义的组和项构建器
  • 高效列表渲染
  • 跨平台兼容性
  • 动态数据更新

适合对象

  • 开发人员构建结构化列表
  • 需要分组数据显示的应用程序
  • 需要可折叠部分的项目
  • 具有层级内容的 UI
  • 使用 Flutter 开发多平台应用的团队

使用建议

  • 需要手动处理组数据结构
  • 有限的内置排序选项
  • 可能需要额外的逻辑来处理复杂的分组
  • 未针对无分页的超大数据集进行优化
  • 标题自定义需要理解小部件组合

原始 README

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

Grouped list package for Flutter.

pub package package publisher build

A flutter ListView in which list items can be grouped to sections.

Features
  • Sound null safety support!
  • Easy creation of chat dialog.
  • List Items can be separated in groups.
  • For the groups an individual header can be set.
  • Almost all fields from ListView.builder available.

Getting Started

Add the package to your pubspec.yaml:

 grouped_list: ^6.0.0

In your dart file, import the library:

import 'package:grouped_list/grouped_list.dart';

Instead of using a ListView create a GroupedListView Widget:

 GroupedListView<dynamic, String>(
   elements: _elements,
   groupBy: (element) => element['group'],
   groupSeparatorBuilder: (String groupByValue) => Text(groupByValue),
   itemBuilder: (context, dynamic element) => Text(element['name']),
   itemComparator: (item1, item2) => item1['name'].compareTo(item2['name']), // optional
   useStickyGroupSeparators: true, // optional
   floatingHeader: true, // optional
   order: GroupedListOrder.ASC, // optional
   footer: Text("Widget at the bottom of list"), // optional
 ),
Parameters:
Name Description Required Default value
elements A list of the data you want to display in the list required -
groupBy Function which maps an element to its grouped value required -
itemBuilder / indexedItemBuilder / interdependentItemBuilder / grouItemBuilder Function which returns an Widget which defines the item.
* indexedItemBuilder provides the current index as well.
* interdependentItemBuilder provides the previous and next items as well.
* groupItemBuilder provides information if the item is the first or last element inside a group.
indexedItemBuilder is preferred over interdependentItemBuilder and interdependentItemBuilder is preferred overitemBuilder.
yes, either of them -
groupSeparatorBuilder / groupHeaderBuilder Function which returns a Widget which defines the group headers. While groupSeparatorBuilder gets the groupBy-value as parameter groupHeaderBuilder gets the whole element. If both are defined groupHeaderBuilder is preferred yes, either of them -
groupStickyHeaderBuilder Function which returns a Widget which defines the sticky group header, when useStickyGroupSeparators is true. If not defined groupSeparatorBuilder or groupHeaderBuilder will be used as described above. no -
useStickyGroupSeparators When set to true the group header of the current visible group will stick on top no false
floatingHeader Whether the sticky group header float over the list or occupy it's own space no false
stickyHeaderBackgroundColor Defines the background color of the sticky header. Will only be used if useStickyGroupSeparators is used no Color(0xffF7F7F7)
separator A Widget which defines a separator between items inside a group no no separator
groupComparator Can be used to define a custom sorting for the groups. Otherwise the natural sorting order is used no -
itemComparator Can be used to define a custom sorting for the elements inside each group. Otherwise the natural sorting order is used no -
order Change to GroupedListOrder.DESC to reverse the group sorting no GroupedListOrder.ASC
footer Widget at the bottom of the list no -

Also the fields from ListView.builder can be used.

Highlight - SilverGroupedList

Now supporting a grouped list based on a silver list. Just use SilverGroupedListView instead of GroupedListView. An example can be found under example/lib/example_silver. Note that some options of the GroupedListView are currently not available in SilverGroupedListView.

Highlight - Chat Dialog

Easy creation of chat dialogs. Just set the option reverse to true and order to GroupedListOrder.DESC. A full example can be found in the examples. The list will be scrolled to the end in the initial state and therefore scrolling will be against redeaing direction.

My other packages :

For easy creation of chat-like dialogs:

Check out my other package StickyGroupedList, which is based on the scrollable_positioned_list.

所属分类

源码仓库

使用此插件的项目