### Install Package Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/README.md Run this command in your terminal to install the package after adding it to pubspec.yaml. ```bash flutter pub add flutter_heatmap_calendar ``` -------------------------------- ### HeatMap onClick Example Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/api-overview.md Example of how to implement the onClick callback in a HeatMap widget to print the tapped date. ```dart HeatMap( onClick: (tappedDate) { print('Tapped: $tappedDate'); }, ) ``` -------------------------------- ### Colorsets Parameter Example Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/types.md Provides an example of the colorsets parameter, a Map, used for color mode selection. Keys represent thresholds, and values are the corresponding Color objects. ```dart const Map colorsets = { 0: Color(0xFFEBEDF0), // Very light 5: Color(0xFFC6E48B), // Light green 10: Color(0xFF7BC96F), // Medium green 25: Color(0xFF239A3B), // Dark green 40: Color(0xFF196127), // Very dark green }; ``` -------------------------------- ### Minimal HeatMap Example Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/quick-reference.md Demonstrates the simplest way to create a HeatMap widget. It requires defining colorsets and datasets. ```dart HeatMap( colorsets: {1: Colors.blue}, datasets: {DateTime(2021, 1, 6): 5}, ) ``` -------------------------------- ### Minimal HeatMapCalendar Example Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/quick-reference.md Shows the most basic implementation of the HeatMapCalendar widget. It requires specifying colorsets and datasets. ```dart HeatMapCalendar( colorsets: {1: Colors.green}, datasets: {DateTime(2021, 1, 6): 5}, ) ``` -------------------------------- ### Minimal HeatMapCalendar Configuration Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/README.md Shows the simplest setup for a HeatMapCalendar widget, which also requires a colorset. ```dart import 'package:flutter_heatmap_calendar/flutter_heatmap_calendar.dart'; // Minimal HeatMapCalendar HeatMapCalendar(colorsets: {1: Colors.green}) ``` -------------------------------- ### Colorsets Example (Opacity Mode) Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/api-overview.md Example of a colorsets Map for ColorMode.opacity. Only the first entry's color is used, with opacity varying based on data values. ```dart const colorsets = { 1: Colors.blue, // Only this used; opacity varies }; ``` -------------------------------- ### Basic HeatMap Widget Configuration Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/README.md Demonstrates the basic setup of the HeatMap widget with datasets, color modes, and click handling. Use this for a simple heatmap display. ```dart import 'package:flutter_heatmap_calendar/flutter_heatmap_calendar.dart'; ... HeatMap( datasets: { DateTime(2021, 1, 6): 3, DateTime(2021, 1, 7): 7, DateTime(2021, 1, 8): 10, DateTime(2021, 1, 9): 13, DateTime(2021, 1, 13): 6, }, colorMode: ColorMode.opacity, showText: false, scrollable: true, colorsets: { 1: Colors.red, 3: Colors.orange, 5: Colors.yellow, 7: Colors.green, 9: Colors.blue, 11: Colors.indigo, 13: Colors.purple, }, onClick: (value) { ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(value.toString()))); }, ); ``` -------------------------------- ### Example Usage of onClick Callback Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/types.md Demonstrates how to implement the onClick callback in a HeatMap widget to display a dialog with data for the clicked date. ```dart HeatMap( onClick: (DateTime clickedDate) { print('User clicked: $clickedDate'); showDialog( context: context, builder: (context) => AlertDialog( title: Text('Data for ${clickedDate.toLocal()}'), content: Text('Value: ${datasets[clickedDate]}'), ), ); }, ) ``` -------------------------------- ### Colorsets Example (Color Mode) Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/api-overview.md Example of a colorsets Map for ColorMode.color. Multiple entries define color thresholds, mapping data values to specific colors. ```dart const colorsets = { 1: Colors.red, 5: Colors.yellow, 10: Colors.green, }; ``` -------------------------------- ### Basic HeatMap with Data Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/README.md A standard example of a HeatMap widget populated with sample data and configured for opacity-based color mode. ```dart HeatMap( datasets: { DateTime(2021, 1, 1): 5, DateTime(2021, 1, 2): 10, DateTime(2021, 1, 3): 3, }, colorsets: {1: Colors.blue}, colorMode: ColorMode.opacity, ) ``` -------------------------------- ### Get Start of Month Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/utility-functions.md Calculates the first day of the month for a given date, setting the time to midnight. Used internally for data filtering. ```dart static DateTime startDayOfMonth(final DateTime referenceDate) { // Returns: DateTime(2021, 6, 1, 0, 0, 0) } ``` -------------------------------- ### Datasets Structure Example Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/api-overview.md Illustrates the structure of the datasets Map, used to provide data values for coloring heatmap blocks. Dates should be normalized to midnight. ```dart final datasets = { DateTime(2021, 1, 1): 5, DateTime(2021, 1, 2): 10, DateTime(2021, 1, 3): 3, DateTime(2021, 1, 4): 7, }; ``` -------------------------------- ### Example Usage of onMonthChange Callback Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/types.md Shows how to use the onMonthChange callback in a HeatMapCalendar to log the new month and trigger data loading for that month. ```dart HeatMapCalendar( onMonthChange: (DateTime newMonth) { print('Month changed to: ${newMonth.year}-${newMonth.month}'); // Load data for new month loadMonthData(newMonth.year, newMonth.month); }, ) ``` -------------------------------- ### Proper DateTime Usage Example Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/types.md Demonstrates the correct way to create DateTime objects for use with the heatmap calendar, emphasizing the exclusion of time components. It also shows how to structure dataset entries. ```dart DateTime properDate = DateTime(2021, 1, 6); // Midnight DateTime improperDate = DateTime(2021, 1, 6, 12, 0); // Noon final Map datasets = { properDate: 5, // Will work // improperDate: 10, // May not match lookups for properDate }; ``` -------------------------------- ### Margin Parameter Examples Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/types.md Demonstrates common usages of the margin parameter, an EdgeInsets object, for controlling the spacing around heatmap blocks. ```dart HeatMap( margin: EdgeInsets.all(2), // All sides 2px margin: EdgeInsets.symmetric(h: 1, v: 2), // Horizontal 1px, vertical 2px ) ``` -------------------------------- ### Basic HeatMapCalendar Widget Configuration Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/README.md Shows the basic setup for the HeatMapCalendar widget, including default color, flexibility, color mode, datasets, and click events. Suitable for calendar-integrated heatmaps. ```dart import 'package:flutter_heatmap_calendar/flutter_heatmap_calendar.dart'; ... HeatMapCalendar( defaultColor: Colors.white, flexible: true, colorMode: ColorMode.color, datasets: { DateTime(2021, 1, 6): 3, DateTime(2021, 1, 7): 7, DateTime(2021, 1, 8): 10, DateTime(2021, 1, 9): 13, DateTime(2021, 1, 13): 6, }, colorsets: const { 1: Colors.red, 3: Colors.orange, 5: Colors.yellow, 7: Colors.green, 9: Colors.blue, 11: Colors.indigo, 13: Colors.purple, }, onClick: (value) { ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(value.toString()))); }, ); ``` -------------------------------- ### HeatMap ColorMode Configuration (Opacity) Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/configuration-reference.md Example of using `ColorMode.opacity` with a single color. The opacity varies proportionally to the data value. ```dart // Use single blue color with varying opacity HeatMap( colorsets: {1: Colors.blue}, colorMode: ColorMode.opacity, ) ``` -------------------------------- ### HeatMap Date Range Configuration (Start and End Dates) Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/configuration-reference.md Sets the `startDate` and `endDate` for the heatmap. The widget adjusts to display full weeks, starting from the Sunday of the week containing `startDate` and potentially extending to the Saturday of the week containing `endDate`. ```dart HeatMap( startDate: DateTime(2020, 1, 1), endDate: DateTime(2021, 1, 1), // Shows 52 weeks from Jan 2020 to Jan 2021 ) ``` ```dart HeatMap( startDate: DateTime(2021, 9, 1), // Automatically displays from Sunday of week containing Sep 1 ) ``` ```dart HeatMap( endDate: DateTime(2021, 6, 30), // Show data up to June 30 ) ``` ```dart HeatMap( // No endDate specified, uses today ) ``` -------------------------------- ### HeatMapCalendar with Month Tracking and Callbacks Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/README.md An example of a HeatMapCalendar with custom color thresholds, flexible layout, and event handlers for month changes and date clicks. ```dart HeatMapCalendar( datasets: monthlyData, colorsets: {0: Colors.grey, 5: Colors.blue, 10: Colors.green}, colorMode: ColorMode.color, flexible: true, onMonthChange: (newMonth) { loadDataForMonth(newMonth.year, newMonth.month); }, onClick: (date) { showDateDetails(date); }, ) ``` -------------------------------- ### Color Tip Helper Parameter Example Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/types.md Shows how to customize the color legend labels using the colorTipHelper parameter, a List. It accepts two widgets for the left and right sides of the legend. ```dart HeatMap( colorTipHelper: [ Row( children: [Icon(Icons.trending_down), Text('Low')], ), Row( children: [Icon(Icons.trending_up), Text('High')], ), ], ) ``` -------------------------------- ### Basic Heatmap with Opacity Mode Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/heatmap.md A basic heatmap example using opacity mode to represent data intensity. It includes sample datasets and a click handler to display the selected date's value. ```dart import 'package:flutter/material.dart'; import 'package:flutter_heatmap_calendar/flutter_heatmap_calendar.dart'; class HeatMapExample extends StatelessWidget { @override Widget build(BuildContext context) { return HeatMap( datasets: { DateTime(2021, 1, 6): 3, DateTime(2021, 1, 7): 7, DateTime(2021, 1, 8): 10, DateTime(2021, 1, 9): 13, DateTime(2021, 1, 13): 6, }, colorMode: ColorMode.opacity, showText: false, scrollable: true, colorsets: { 1: Colors.red, 3: Colors.orange, 5: Colors.yellow, 7: Colors.green, 9: Colors.blue, 11: Colors.indigo, 13: Colors.purple, }, onClick: (value) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(value.toString())), ); }, ); } } ``` -------------------------------- ### Datasets Parameter Example Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/types.md Illustrates the structure of the datasets parameter, a Map, used to provide data values for the heatmap. Keys must be DateTime objects normalized to midnight. ```dart final Map datasets = { DateTime(2021, 1, 1): 5, DateTime(2021, 1, 2): 10, DateTime(2021, 1, 3): 3, }; ``` -------------------------------- ### HeatMap ColorMode Configuration (Color) Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/_autodocs/configuration-reference.md Example of using `ColorMode.color` with multiple colors. Data values are mapped to discrete color ranges defined by the thresholds in `colorsets`. ```dart // Use discrete colors for value ranges HeatMap( colorsets: {0: red, 10: yellow, 20: green}, colorMode: ColorMode.color, ) ``` -------------------------------- ### Flutter Web Service Worker Setup Source: https://github.com/devappmin/flutter_heatmap_calendar/blob/main/example/web/index.html This JavaScript code handles the registration and management of a service worker for a Flutter web application. It includes logic for updating the service worker, waiting for activation, and falling back to a plain script tag if the service worker fails to load. ```javascript var serviceWorkerVersion = null; var scriptLoaded = false; function loadMainDartJs() { if (scriptLoaded) { return; } scriptLoaded = true; var scriptTag = document.createElement('script'); scriptTag.src = 'main.dart.js'; scriptTag.type = 'application/javascript'; document.body.append(scriptTag); } if ('serviceWorker' in navigator) { // Service workers are supported. Use them. window.addEventListener('load', function () { // Wait for registration to finish before dropping the