Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes on calculation of event and display color added for event label #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/calendar_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CalendarEvent {
required this.eventDate,
required this.eventTextStyle,
this.eventBackgroundColor = Colors.blue,
this.eventTypeBorderColor,
this.eventID,
});

Expand All @@ -17,4 +18,5 @@ class CalendarEvent {
final DateTime eventDate;
final String? eventID;
final Color eventBackgroundColor;
final Color? eventTypeBorderColor;
}
94 changes: 60 additions & 34 deletions lib/src/components/days_row/event_labels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const dayLabelContentHeight = 16;
const dayLabelVerticalMargin = 4;
const _dayLabelHeight = dayLabelContentHeight + (dayLabelVerticalMargin * 2);

const _eventLabelContentHeight = 13;
const _eventLabelContentHeight = 16;
const _eventLabelBottomMargin = 3;
const _eventLabelHeight = _eventLabelContentHeight + _eventLabelBottomMargin;

Expand Down Expand Up @@ -43,9 +43,10 @@ class EventLabels extends HookConsumerWidget {
}

int _maxIndex(double cellHeight, int eventsLength) {
final spaceForEvents = cellHeight - _dayLabelHeight;
double spaceForEvents = cellHeight - _dayLabelHeight;
const indexing = 1;
const indexForPlot = 1;
// spaceForEvents = spaceForEvents - (_eventLabelHeight + 13);
return spaceForEvents ~/ _eventLabelHeight - (indexing + indexForPlot);
}

Expand All @@ -56,51 +57,76 @@ class EventLabels extends HookConsumerWidget {
return const SizedBox.shrink();
}
final eventsOnTheDay = _eventsOnTheDay(date, events);
final hasEnoughSpace = _hasEnoughSpace(cellHeight, eventsOnTheDay.length);
final maxIndex = _maxIndex(cellHeight, eventsOnTheDay.length);
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: eventsOnTheDay.length,
itemBuilder: (context, index) {
if (hasEnoughSpace) {
return _EventLabel(eventsOnTheDay[index]);
} else if (index < maxIndex) {
return _EventLabel(eventsOnTheDay[index]);
} else if (index == maxIndex) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_EventLabel(
eventsOnTheDay[index],
// final maxIndex = _maxIndex(cellHeight, eventsOnTheDay.length);
// final hasEnoughSpace = eventsOnTheDay.length >
// (maxIndex + 1); //_hasEnoughSpace(cellHeight, eventsOnTheDay.length);

final maxEventCount = (cellHeight / _eventLabelHeight)
.toInt(); //_maxIndex(cellHeight, eventsOnTheDay.length);
final hasEnoughSpace = eventsOnTheDay.length <= maxEventCount;
final maxIndex = maxEventCount - 1;
return Container(
height: cellHeight,
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: eventsOnTheDay.length,
itemBuilder: (context, index) {
if (hasEnoughSpace) {
return _EventLabel(
event: eventsOnTheDay[index],
bottomSpace: 0.0,
);
} else if (index < (maxIndex - 1)) {
return _EventLabel(event: eventsOnTheDay[index], bottomSpace: 0.0);
} else if (index == (maxIndex - 1)) {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_EventLabel(
event: eventsOnTheDay[index],
bottomSpace: 0,
),
Center(
child: Text(
'${eventsOnTheDay.length - (maxIndex)}+',
style: TextStyle(color: Colors.blue),
),
)
],
),
Icon(
Icons.more_horiz,
size: 13,
)
],
);
} else {
return SizedBox.shrink();
}
},
);
} else {
return SizedBox.shrink();
}
},
),
);
}
}

/// label to show [CalendarEvent]
class _EventLabel extends StatelessWidget {
_EventLabel(this.event);

final double? bottomSpace;
final CalendarEvent event;

_EventLabel({required this.event, this.bottomSpace});

@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(right: 4, bottom: 3),
height: 13,
margin: EdgeInsets.only(
right: 4,
bottom: this.bottomSpace ?? _eventLabelBottomMargin.toDouble()),
height: _eventLabelContentHeight.toDouble(),
alignment: Alignment.center,
width: double.infinity,
color: event.eventBackgroundColor,
decoration: BoxDecoration(
color: event.eventTypeColor ?? event.eventBackgroundColor,
border: Border.all(
color: event.eventTypeBorderColor ?? event.eventBackgroundColor),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
child: Text(
event.eventName,
style: event.eventTextStyle,
Expand Down