MCalendarController class

An imperative controller for an MCalendar instance.

Use an MCalendarController to programmatically change the displayed month, navigate forward or backward, select dates or ranges, and query the current selection. Works across monthly, weekly, and horizontal calendar layouts.

Listeners added to MCalendarController are automatically notified whenever the user interacts with the calendar or when programmatic changes occur.

final controller = MCalendarController();

controller.addListener(() {
  print('Selected: ${controller.selectedDates}');
});

// In your widget:
MCalendar(
  controller: controller,
  selectedMonth: DateTime(2026, 3),
  onUserPicked: (dates) => print(dates),
)

// Later:
controller.nextMonth();
controller.selectDate(DateTime(2026, 3, 20));
Inheritance

Constructors

MCalendarController({DateTime? initialMonth})
Creates an MCalendarController optionally initialized to initialMonth.

Properties

displayedMonth DateTime
The currently displayed month (normalized to year and month only).
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
initialMonth DateTime?
The optional initial month provided at construction.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectedDates List<DateTime>
The currently selected dates, if any.
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
attach(Object provider) → void
Attaches a provider to this controller.
clearSelection() → void
Clears the current selection.
detach() → void
Detaches all currently attached providers.
dispose() → void
Discards any resources used by the object.
override
nextMonth() → void
Advances the calendar by one month.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
previousMonth() → void
Moves the calendar back by one month.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
selectDate(DateTime date) → void
Programmatically selects a single date.
selectRange(DateTime start, DateTime end) → void
Programmatically selects a range between start and end.
setMonth(DateTime month) → void
Programmatically changes the displayed month and notifies listeners.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited