Skip to content

Commit

Permalink
refactor(calendar): Some more null checks in reaction to an app crash…
Browse files Browse the repository at this point in the history
… log possibly related to this package
  • Loading branch information
agfeo-rw committed Sep 3, 2024
1 parent ca43df9 commit 85b03f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.4.13] - 2024-09-03
* Some more null checks in reaction to an app crash log possibly related to this package

## [0.4.12] - 2024-08-30
* Issue 86: Updtae of the eventlist now works every time

Expand Down
58 changes: 35 additions & 23 deletions lib/flutter_neat_and_clean_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,26 @@ class _CalendarState extends State<Calendar> {
forceEventListView = widget.forceEventListView;

_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)}';
}));

if (widget.locale != null) {
initializeDateFormatting(widget.locale, null).then((_) {
if (mounted) {
setState(() {
var monthFormat =
DateFormat('MMMM yyyy', widget.locale).format(_selectedDate);
displayMonth =
'${monthFormat[0].toUpperCase()}${monthFormat.substring(1)}';
});
}
}).catchError((error) {
widget.onPrintLog != null
? widget.onPrintLog!('Error initializing date formatting: $error')
: print('Error initializing date formatting: $error');
});
} else {
widget.onPrintLog != null
? widget.onPrintLog!('widget.locale is null')
: print('widget.locale is null');
}
// When setting the initial date, the eventsmap must be updated. The eventsmap is used to
// store the events for each day. The eventsmap is used to display the events in the calendar.
// It is basically the internal store of the events. Because the events are passed as a list
Expand Down Expand Up @@ -334,6 +347,7 @@ class _CalendarState extends State<Calendar> {
// at the same time. In that case the map will be used, while the list is omitted.
if (widget.eventsList != null &&
widget.eventsList!.isNotEmpty &&
eventsMap != null &&
eventsMap!.isEmpty) {
widget.eventsList!.forEach((event) {
final int range = event.endTime.difference(event.startTime).inDays;
Expand All @@ -354,7 +368,7 @@ class _CalendarState extends State<Calendar> {
event.startTime.month,
event.startTime.day + i)] ??
[];
// Iteration over the range (diferrence between start and end time in days).
// Iteration over the range (difference between start and end time in days).
NeatCleanCalendarEvent newEvent = NeatCleanCalendarEvent(
event.summary,
description: event.description,
Expand Down Expand Up @@ -419,7 +433,7 @@ class _CalendarState extends State<Calendar> {
// If the eventsMap is updated, the eventsUpdated callback is invoked. In some cases it is useful
// to have a copy of the eventsMap in the parent widget. This can be done by providing a callback
// method to the calendar widget.
if (widget.onEventsUpdated != null) {
if (widget.onEventsUpdated != null && eventsMap != null) {
widget.onEventsUpdated!(eventsMap!);
}
}
Expand Down Expand Up @@ -577,24 +591,23 @@ class _CalendarState extends State<Calendar> {
),
)
: Container(),
Expanded(
child: Container()), // Placeholder to balance the Row
Expanded(child: Container()), // Placeholder to balance the Row
forceEventListView ? Container() : jumpDateIcon ?? Container(),
forceEventListView ? Container() : rightArrow ?? Container(),
],
),
// Zentralisiertes Stack-Widget
GestureDetector(
child: Column(children: [
if (todayIcon != null) todayIcon!,
Text(
displayMonth,
style: widget.displayMonthTextStyle ??
TextStyle(
fontSize: 20.0,
),
),
]),
child: Column(children: [
if (todayIcon != null) todayIcon!,
Text(
displayMonth,
style: widget.displayMonthTextStyle ??
TextStyle(
fontSize: 20.0,
),
),
]),
onTap: () {
if (widget.onTodayButtonPressed != null) {
widget.onTodayButtonPressed!(_selectedDate);
Expand All @@ -605,8 +618,7 @@ class _CalendarState extends State<Calendar> {
(forceEventListView && _scrollController.hasClients)) {
resetToToday();
}
}
),
}),
],
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.12
version: 0.4.13
homepage: https://github.com/rwbr/flutter_neat_and_clean_calendar

environment:
Expand Down

0 comments on commit 85b03f5

Please sign in to comment.