diff --git a/CHANGELOG.md b/CHANGELOG.md index 15cbee6..2830f9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ -## [0.3.6+19] - 2022-06-30 +## [0.3.7+20] - 2022-06-30 * Support for macOS widgets +## [0.3.6+19] - 2022-06-03 +* Issue #37 closed + ## [0.3.5+18] - 2022-05-04 * Option to change color of selected day when same date as today diff --git a/lib/flutter_neat_and_clean_calendar.dart b/lib/flutter_neat_and_clean_calendar.dart index 58aa470..94a53a8 100644 --- a/lib/flutter_neat_and_clean_calendar.dart +++ b/lib/flutter_neat_and_clean_calendar.dart @@ -186,6 +186,19 @@ class _CalendarState extends State { super.initState(); isExpanded = widget.isExpanded; + _selectedDate = widget.initialDate ?? DateTime.now(); + initializeDateFormatting(widget.locale, null).then((_) => setState(() { + var monthFormat = + DateFormat('MMMM yyyy', widget.locale).format(_selectedDate); + displayMonth = + '${monthFormat[0].toUpperCase()}${monthFormat.substring(1)}'; + })); + } + + /// The method [_updateEventsMap] has the purpose to update the eventsMap, when the calendar widget + /// renders its view. When this method executes, it fills the eventsMap with the contents of the + /// given eventsList. This can be used to update the events shown by the calendar. + void _updateEventsMap() { eventsMap = widget.events ?? {}; // If the user provided a list of events, then convert it to a map, but only if there // was no map of events provided. To provide the events in form of a map is the way, @@ -261,21 +274,16 @@ class _CalendarState extends State { } }); } - - _selectedDate = widget.initialDate ?? DateTime.now(); selectedMonthsDays = _daysInMonth(_selectedDate); selectedWeekDays = Utils.daysInRange( _firstDayOfWeek(_selectedDate), _lastDayOfWeek(_selectedDate)) .toList(); - initializeDateFormatting(widget.locale, null).then((_) => setState(() { - var monthFormat = - DateFormat('MMMM yyyy', widget.locale).format(_selectedDate); - displayMonth = - '${monthFormat[0].toUpperCase()}${monthFormat.substring(1)}'; - })); + _selectedEvents = eventsMap?[DateTime( _selectedDate.year, _selectedDate.month, _selectedDate.day)] ?? []; + + print('eventsMap has ${eventsMap?.length} entries'); } Widget get nameAndIconRow { @@ -715,6 +723,8 @@ class _CalendarState extends State { @override Widget build(BuildContext context) { + _updateEventsMap(); + // If _selectedEvents is not null, then we sort the events by isAllDay propeerty, so that // all day events are displayed at the top of the list. // Slightly inexxficient, to do this sort each time, the widget builds. diff --git a/pubspec.lock b/pubspec.lock index dc88f7b..f72c46a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -157,5 +157,5 @@ packages: source: hosted version: "2.1.2" sdks: - dart: ">=2.17.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index c756e36..e601a15 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: >- Simple and clean flutter calendar with ability to slide up/down to show weekly/monthly calendar. Fork of https://pub.dev/packages/flutter_clean_calendar -version: 0.3.6+19 +version: 0.3.7+20 homepage: https://github.com/rwbr/flutter_neat_and_clean_calendar environment: