grouped_list_by_date 0.1.2 copy "grouped_list_by_date: ^0.1.2" to clipboard
grouped_list_by_date: ^0.1.2 copied to clipboard

A Flutter package for creating grouped lists by date (Today, Yesterday, This Week, etc.).

Grouped List by Date #

A Flutter package to easily group items by date categories such as Today, Yesterday, This Week, Previous Week, and Earlier. It simplifies the task of displaying lists grouped by dates, making it ideal for apps that need to display content based on time frames.

Features #

  • Group items by date categories: Today, Yesterday, This Week, Previous Week, and Earlier
  • Customizable item rendering via itemBuilder
  • Seamless integration with StatefulWidget for dynamic data updates
  • Lightweight and easy to use

Getting started #

To get started with this package, you’ll need to include it in your project’s pubspec.yaml file:

dependencies:
  grouped_list_by_date: ^0.1.2

Usage #

Here’s a short example demonstrating how to use the GroupedListByDate package in your Flutter app: Add longer examples to /example folder.

import 'package:flutter/material.dart';
import 'package:grouped_list_by_date/grouped_list_by_date.dart';
import 'package:intl/intl.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: GroupedListExample(),
    );
  }
}

class GroupedListExample extends StatelessWidget {
  final List<Map<String, dynamic>> items = [
    {'name': 'Task 1', 'date': DateTime.now()},
    {
      'name': 'Task 2',
      'date': DateTime.now().subtract(const Duration(days: 1))
    },
    {
      'name': 'Task 3',
      'date': DateTime.now().subtract(const Duration(days: 3))
    },
    {
      'name': 'Task 4',
      'date': DateTime.now().subtract(const Duration(days: 8))
    },
    {
      'name': 'Task 5',
      'date': DateTime.now().subtract(const Duration(days: 10))
    },
  ];

  GroupedListExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Grouped List by Date'),
      ),
      body: GroupedListByDate(
        items: items,
        itemCount: items.length,
        groupByParameter: 'date',
        stickyHeader: true,
        headingChild: (heading) => Padding(
          padding: const EdgeInsets.all(18.0),
          child: Text(
            heading,
            style: const TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Colors.white),
          ),
        ),
        itemBuilder: (context, item) {
          return Card(
            shape:
            RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
            child: ListTile(
              title: Text(item['name']),
              subtitle: Text(DateFormat('dd MMM yyyy').format(item['date'])),
            ),
          );
        },
      ),
    );
  }
}

Additional information #

Source Code: You can find the source code and contribute to the project on GitHub. Issues: If you encounter any issues or bugs, feel free to open an issue. Contributions: Contributions are welcome! If you'd like to contribute, please fork the repository, make your changes, and submit a pull request.

For further details, check the example code in the /example directory.

0
likes
140
points
12
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for creating grouped lists by date (Today, Yesterday, This Week, etc.).

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_sticky_header, intl

More

Packages that depend on grouped_list_by_date