genericlistwithdate 0.0.1
genericlistwithdate: ^0.0.1 copied to clipboard
A Flutter widget that displays a list grouped by date.
Generic Date List View #
A Flutter package that provides a customizable list view displaying items grouped by date. This widget is ideal for applications that require displaying messages, events, or any data that can be categorized by date, such as chat messages or logs.
Usage Here's how to use the GenericDateListView in your Flutter app:
Import the package:
dart Copy code import 'package:genericlistwithdate/genericlistwithdate.dart'; Create a sample data model:
You can create any model for your data. For this example, let’s assume you have a simple message model:
dart Copy code class Message { final String content; final DateTime timestamp;
Message(this.content, this.timestamp); } Prepare your data:
Create a list of messages:
dart Copy code List
Here's an example of how to implement it in your widget tree:
dart Copy code @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Date Grouped List View")), body: GenericDateListView
Example Scenario:
A user opens the chat screen and sees messages grouped under today's date, yesterday's date, and earlier dates. This makes it easier for users to locate conversations from specific days without scrolling through an unorganized list. Here's how you can implement this in a chat application:
dart Copy code class ChatMessage { final String content; final DateTime timestamp;
ChatMessage(this.content, this.timestamp); }
class ChatScreen extends StatelessWidget { @override Widget build(BuildContext context) { List
return Scaffold(
appBar: AppBar(title: Text("Chat")),
body: GenericDateListView<ChatMessage>(
dataList: chatMessages,
extractDate: (message) => message.timestamp.toIso8601String(),
itemBuilder: (context, message) {
return ListTile(
title: Text(message.content),
subtitle: Text(message.timestamp.toString()),
);
},
),
);
} } Example Here's a complete example for a better understanding:
dart Copy code import 'package:flutter/material.dart'; import 'package:genericlistwithdate/genericlistwithdate.dart';
class Message { final String content; final DateTime timestamp;
Message(this.content, this.timestamp); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { List
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text("Date Grouped List View")),
body: GenericDateListView<Message>(
dataList: messages,
extractDate: (message) => message.timestamp.toIso8601String(),
itemBuilder: (context, message) {
return ListTile(
title: Text(message.content),
subtitle: Text(message.timestamp.toString()),
);
},
),
),
);
} }
void main() { runApp(MyApp()); } Contributions Contributions are welcome! If you have suggestions or improvements, feel free to open an issue or submit a pull request.
License This package is licensed under the MIT License. See the LICENSE file for details.
Contact For any questions or inquiries, feel free to reach out:
Author: Earbaj Md Saria Email: earbajsaria3@gmail.com