horizontal_calendar_badge 0.0.4 copy "horizontal_calendar_badge: ^0.0.4" to clipboard
horizontal_calendar_badge: ^0.0.4 copied to clipboard

A customizable horizontal calendar widget with badge support

example/main.dart

import 'package:flutter/material.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:horizontal_calendar_badge/horizontal_calendar_badge.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize locale for formatting (e.g. 'ta' for Tamil)
  await initializeDateFormatting('ta');

  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Horizontal Calendar Badge Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const CalendarDemoPage(),
    );
  }
}

class Complaint {
  final String name;
  final String createdDateTime;

  Complaint({required this.name, required this.createdDateTime});
}

class CalendarDemoPage extends StatefulWidget {
  const CalendarDemoPage({super.key});

  @override
  State<CalendarDemoPage> createState() => _CalendarDemoPageState();
}

class _CalendarDemoPageState extends State<CalendarDemoPage> {
  DateTime? selectedDate;
  late List<Complaint> complaints;
  late List<Complaint> filteredComplaints;

  @override
  void initState() {
    super.initState();

    // Sample data
    complaints = [
      Complaint(name: 'Noise', createdDateTime: '2025-07-06'),
      Complaint(name: 'Garbage', createdDateTime: '2025-07-06'),
      Complaint(name: 'Light', createdDateTime: '2025-07-05'),
      Complaint(name: 'Water', createdDateTime: '2025-07-03'),
      Complaint(name: 'Road', createdDateTime: '2025-07-02'),
    ];

    filteredComplaints = complaints;
  }

  void applyFilters() {
    setState(() {
      filteredComplaints = complaints.where((complaint) {
        final complaintDate = DateTime.parse(complaint.createdDateTime);
        return selectedDate == null ||
            (complaintDate.year == selectedDate!.year &&
                complaintDate.month == selectedDate!.month &&
                complaintDate.day == selectedDate!.day);
      }).toList();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Horizontal Calendar Example')),
      body: Column(
        children: [
          CustomHorizontalCalendar<Complaint>(
            selectedDate: selectedDate,
            onDateSelected: (date) {
              setState(() {
                selectedDate = date;
                applyFilters();
              });
            },
            items: complaints,
            getItemDate: (item) => DateTime.parse(item.createdDateTime),
            locale: 'ta', // Try 'en', 'hi', etc.
            daysBack: 10,
          ),
          const Divider(),
          Expanded(
            child: ListView.builder(
              itemCount: filteredComplaints.length,
              itemBuilder: (context, index) {
                final complaint = filteredComplaints[index];
                return ListTile(
                  title: Text(complaint.name),
                  subtitle: Text(complaint.createdDateTime),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
6
likes
150
points
13
downloads

Publisher

unverified uploader

Weekly Downloads

A customizable horizontal calendar widget with badge support

Documentation

API reference

License

MIT (license)

Dependencies

flutter, intl

More

Packages that depend on horizontal_calendar_badge