CalendarMonthViewModel constructor

CalendarMonthViewModel(
  1. BuildContext context, {
  2. AbstractApiInterface? apiInterface,
  3. DateTime? initialDate,
})

Creates a CalendarMonthViewModel with the given repository and template provider.

It listens to changes in the CalendarTemplateProvider to refetch events when the selected template changes.

Implementation

CalendarMonthViewModel(BuildContext context,
    {AbstractApiInterface? apiInterface, DateTime? initialDate})
    : _calendarRepository =
          context.read<CalendarMonthRepository>(), // Read from Provider
      _templateProvider = context.read<CalendarTemplateProvider?>(),
      _displayDate = initialDate ??
          (() {
            final now = DateTime.now();
            return DateTime.utc(now.year, now.month, now.day);
          })() {
  // Initialize _displayDate here
  _templateProvider?.addListener(_onDependenciesChanged);
}