Skip to content

Calendar Views — cdx_calendar_view

cdx_calendar_view is the CDX query-driven calendar shell. Use it when a collection is naturally organized by date while the right side remains an ordinary detail surface.

dart
import 'package:cdx_calendar_view/cdx_calendar_view.dart';

Live Example

Open the full route: Calendar View.

When To Use It

Use a calendar view when the primary question is what is scheduled or active on this date range?

Good fits:

ScenarioPattern
Scheduled activitiesCalendar rail selects a day/week/month; detail pane shows rows
Maintenance plansDate buckets show upcoming work and overdue work
Training eventsMonth or week mode selects sessions for a table/detail pane
Release windowsDate range drives a filtered entity list

Model

Calendar view data flowCalendarQuery belongs to the data source. The controller loads buckets and selected item pages, then CalendarShell renders the rail and delegates details to the host.CalendarQuerydate field, root filter,search, orderDataSourcefetchBuckets(range)fetchItems(range,page)Controllerbucket cache, selectedrange, row pagesCalendarShell: rail + host detailBuilder
text
CalendarQuery
  -> CalendarDataSource<T>
  -> CalendarController<T>
  -> CalendarShell<T>

CalendarQuery composes root filters, search, sorting, and selected date ranges through cdx_query. CalendarDataSource<T> owns transport. CalendarController<T> owns buckets, selected range, and selected rows. CalendarShell<T> renders the resizable calendar rail and delegates the right side to your builder.

Calendar Shell

dart
class ActivityCalendarDataSource extends CalendarDataSource<Activity> {
  ActivityCalendarDataSource(ActivityApi api)
    : _api = api,
      super(
        CalendarQuery(
          dateField: 'scheduled_at',
          baseFilter: siteFilter,
        ),
      );

  final ActivityApi _api;

  @override
  Future<List<CalendarDateBucket>> fetchBuckets(CalendarDateRange range) {
    return _api.fetchDateBuckets(
      groupBy: query.bucketGroupBy(),
      filter: query.filterForRange(range),
    );
  }

  @override
  Future<CalendarItemsPage<Activity>> fetchItems(
    CalendarDateRange range, {
    int limit = 20,
    int offset = 0,
  }) {
    return _api.fetchActivities(
      filter: query.filterForRange(range),
      search: query.search,
      orderBy: query.orderBy,
      limit: limit,
      offset: offset,
    );
  }
}

final controller = CalendarController<Activity>(
  dataSource: ActivityCalendarDataSource(api),
);

CalendarShell<Activity>(
  controller: controller,
  detailBuilder: (context, controller) {
    return ActivityTable(
      range: controller.selectedRange,
      items: controller.items,
      total: controller.total,
      page: controller.page,
      onPageChanged: controller.goToPage,
    );
  },
);

The renderer is CDX-owned. Year, month, and week modes share the same grid treatment so spacing, disabled state, selection, and count rendering stay consistent across modes.

Query Boundary

The calendar contributes a date-range filter. The detail surface can still own its own search, sort, and extra filters:

text
calendar date range filter
AND base filter
AND detail search/filter/sort

That keeps the calendar as context while preserving the ergonomics of a normal table, kanban, or detail pane.

API Parameters

TypeParameterPurpose
CalendarQuerydateFieldQuery field used for buckets and selected-range filters.
CalendarQuerybaseFilterPredicate applied to every bucket and selected-detail fetch.
CalendarQuerysearchOptional free-text search for concrete data sources.
CalendarQueryorderByOrdering for selected-detail rows.
CalendarQuerytimezoneOptional bucketing timezone.
CalendarDataSourcequeryOwned by the source, not the controller.
CalendarControllerpageSizeRow page size for selected-range detail fetches.
CalendarControllermaxCachedBucketRangesNumber of visible bucket ranges kept in memory.
CalendarShelldateFields, selectedDateFieldOptional field switcher in the calendar rail.
CalendarShellonDateFieldChanged, onModeChanged, onFocusedDayChanged, onSelectedRangeChangedHost callbacks for shell state changes.