I’m using the DayView widget from the calendar_view (https://pub.dev/packages/calendar_view) package in my Flutter app to display events for a selected day. I want to dynamically update the initialDay of DayView whenever a new date is selected from a calendar. However, changing the initialDay value doesn’t seem to update the DayView.
Here’s a simplified version of my code:
import 'package:flutter/material.dart';
import 'package:calendar_view/calendar_view.dart';
import 'package:intl/intl.dart';
class HourlyView extends StatelessWidget {
final List<EventModel> events;
final DateTime initialDate;
HourlyView({required this.events, required this.initialDate});
@override
Widget build(BuildContext context) {
EventController eventController = EventController();
// Map EventModel to CalendarEventData and add to controller
events.forEach((event) {
eventController.add(
CalendarEventData(
date: event.start,
startTime: event.start,
endTime: event.end,
title: event.summary,
),
);
});
return Container(
color: Colors.black, // Set the background color to black
child: DayView(
controller: eventController,
initialDay: initialDate,
// Other properties...
),
);
}
}
Even though the initialDay is updated, the DayView does not refresh to show the new date. How can I ensure that the DayView updates correctly when the initialDay changes?
Additional Context:
- I’m using a ValueNotifier to handle the selected date changes in my calendar view.
- The DayView widget seems to initialize with the correct date but does not update dynamically.