grouped_list 1.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

Grouped list package for Flutter #

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

Getting Started #

Add the package to your pubspec.yaml:

 grouped_list: ^1.2.1

In your dart file, import the library:

import 'package:grouped_list/grouped_list.dart';

Instead of using a ListView create a GroupedListView Widget:

  GroupedListView(
    elements: _elements,
    groupBy: (element) => element['group'],
    groupSeparatorBuilder: _buildGroupSeparator,
    itemBuilder: (context, element) => Text(element['name']),
  ),

You can also use most fields from the ListView.builder constructor.

Required Parameters: #

  • elements: A list of the data you want to display in the list.
  • groupBy: Function which maps an element to its grouped value.
  • itemBuilder: Function which returns an Widget which defines the item.
  • groupSeparator: Function which returns an Widget which defines the section separator.
Widget _buildGroupSeparator(dynamic groupByValue) {
  return Text('$groupByValue');
}

The parameter groupByValue has the return type of the defined groupBy function.

Optional Parameters: #

  • separator: A Widget which defines a separator between items inside a section.
  • sort: A bool which defines if the passed data should be sorted by the widget. By default it's true.

Notice: #

  • The item builder functions only creates the actual list items. For seperator items use the separator parameter.
  • Other than the itemBuilder function of the ListView.builder constructor the function provides the specific element instead of the index as parameter.
  • The elements need to be sorted according to the groupBy return value. The Widgets sorts the elements by default. Disable the sorting only if your list is sorted beforehand.

[1.0.0] - 13.08.2019

  • Initial release

[1.1.0] - 14.08.2019

  • Added example
  • Edited readme and package description

[1.2.0] - 15.08.2019

  • Widget sort the list elements now according the groupByvalue. Can be switched off through the parameter sort

[1.2.1] - 18.08.2019

  • Improved documentary

example/example.dart

import 'package:flutter/material.dart';
import 'package:grouped_list/grouped_list.dart';

void main() => runApp(MyApp());

List _elements = [
  {'name': 'John', 'group': 'Team A'},
  {'name': 'Will', 'group': 'Team B'},
  {'name': 'Beth', 'group': 'Team A'},
  {'name': 'Miranda', 'group': 'Team B'},
  {'name': 'Mike', 'group': 'Team C'},
  {'name': 'Danny', 'group': 'Team C'},
];

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Grouped List View Example'),
        ),
        body: GroupedListView<dynamic, String>(
          groupBy: (element) => element['group'],
          elements: _elements,
          sort: true,
          groupSeparatorBuilder: (String value) => Padding(
            padding: const EdgeInsets.all(8.0),
            child: Center(
                child: Text(
              value,
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            )),
          ),
          itemBuilder: (c, element) {
            return Card(
              elevation: 8.0,
              margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
              child: Container(
                child: ListTile(
                  contentPadding:
                      EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
                  leading: Icon(Icons.account_circle),
                  title: Text(element['name']),
                  trailing: Icon(Icons.arrow_forward),
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  grouped_list: ^1.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:grouped_list/grouped_list.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
84
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Dec 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.2

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test