Skip to content

Commit

Permalink
Add custom rendering priority for SelectedDay and Today
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksanderwozniak committed Apr 27, 2019
1 parent aa17a4b commit 8af5726
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions lib/src/customization/calendar_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class CalendarStyle {
/// This property defines if those should be visible (eg. with custom style) or hidden.
final bool outsideDaysVisible;

/// Determines rendering priority for SelectedDay and Today.
/// * `true` - SelectedDay will have higher priority than Today
/// * `false` - Today will have higher priority than SelectedDay
final bool renderSelectedFirst;

const CalendarStyle({
this.weekdayStyle = const TextStyle(),
this.weekendStyle = const TextStyle(color: const Color(0xFFF44336)), // Material red[500]
Expand All @@ -83,5 +88,6 @@ class CalendarStyle {
this.markersPositionRight,
this.markersMaxAmount = 4,
this.outsideDaysVisible = true,
this.renderSelectedFirst = true,
});
}
4 changes: 2 additions & 2 deletions lib/src/customization/header_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class HeaderStyle {
final bool formatButtonVisible;

/// Controls the text inside FormatButton.
/// When `true`, the button will show next CalendarFormat.
/// When `false`, the button will show current CalendarFormat.
/// * `true` - the button will show next CalendarFormat
/// * `false` - the button will show current CalendarFormat
final bool formatButtonShowsNext;

/// Use to customize header's title text (eg. with different `DateFormat`).
Expand Down
18 changes: 8 additions & 10 deletions lib/src/widgets/cell_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,24 @@ class CellWidget extends StatelessWidget {
}

Decoration _buildCellDecoration() {
if (isSelected) {
return BoxDecoration(
shape: BoxShape.circle,
color: calendarStyle.selectedColor,
);
if (isSelected && calendarStyle.renderSelectedFirst) {
return BoxDecoration(shape: BoxShape.circle, color: calendarStyle.selectedColor);
} else if (isToday) {
return BoxDecoration(
shape: BoxShape.circle,
color: calendarStyle.todayColor,
);
return BoxDecoration(shape: BoxShape.circle, color: calendarStyle.todayColor);
} else if (isSelected) {
return BoxDecoration(shape: BoxShape.circle, color: calendarStyle.selectedColor);
} else {
return BoxDecoration(shape: BoxShape.circle);
}
}

TextStyle _buildCellTextStyle() {
if (isSelected) {
if (isSelected && calendarStyle.renderSelectedFirst) {
return calendarStyle.selectedStyle;
} else if (isToday) {
return calendarStyle.todayStyle;
} else if (isSelected) {
return calendarStyle.selectedStyle;
} else if (isOutsideMonth && isHoliday) {
return calendarStyle.outsideHolidayStyle;
} else if (isHoliday) {
Expand Down
4 changes: 3 additions & 1 deletion lib/table_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,12 @@ class _TableCalendarState extends State<TableCalendar> with SingleTickerProvider
final isOutside = widget.builders.outsideDayBuilder != null && tIsOutside && !tIsWeekend && !tIsHoliday;
final isWeekend = widget.builders.weekendDayBuilder != null && !tIsOutside && tIsWeekend && !tIsHoliday;

if (isSelected) {
if (isSelected && widget.calendarStyle.renderSelectedFirst) {
return widget.builders.selectedDayBuilder(context, date, widget.events[eventKey]);
} else if (isToday) {
return widget.builders.todayDayBuilder(context, date, widget.events[eventKey]);
} else if (isSelected) {
return widget.builders.selectedDayBuilder(context, date, widget.events[eventKey]);
} else if (isOutsideHoliday) {
return widget.builders.outsideHolidayDayBuilder(context, date, widget.events[eventKey]);
} else if (isHoliday) {
Expand Down

0 comments on commit 8af5726

Please sign in to comment.