calculateVerticalLayoutData method
Vertical layout of the events.
Calculates the top and bottom of each event, and ensues that they are within the bounds of the widget.
size - The size of the widget.
Implementation
List<VerticalLayoutData> calculateVerticalLayoutData(Size size) {
final numberOfChildren = events.length;
final currentCache = <int, VerticalLayoutData>{};
final cache = layoutCache.getCache(date, heightPerMinute, timeOfDayRange);
if (cache == null) {
// If there is no cache, calculate the layout data for each event.
for (var i = 0; i < numberOfChildren; i++) {
final id = i;
final event = events.elementAt(i);
final eventHash = event.hashCode;
currentCache[eventHash] = _calculateSingleEventLayout(id, size, event);
}
} else {
// If there is a cache, use it to calculate the layout data for each event.
for (var i = 0; i < numberOfChildren; i++) {
final id = i;
final event = events.elementAt(i);
final eventHash = event.hashCode;
final cached = cache[eventHash];
if (cached == null) {
currentCache[eventHash] = _calculateSingleEventLayout(id, size, event);
} else {
currentCache[eventHash] = cached.copyWith(id: id);
}
}
}
layoutCache.setCache(date, heightPerMinute, timeOfDayRange, currentCache);
return sortVerticalLayoutData(currentCache.values.toList());
}